'Task <User>'不包含'LastActive'的定义

时间:2019-12-03 18:16:07

标签: c# asp.net-core asp.net-web-api

这是我的.cs代码,正在生成错误(第23行):“任务”不包含“ LastActive”的定义,并且没有可访问的扩展方法“ LastActive”接受类型为“ Task”的第一个参数被发现

using System.Security.Claims;
using System.Threading.Tasks;
using DatingApp.Data;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection;
using DatingApp.Models;
namespace DatingApp.Helper
{
    public class LogUserActivity : IAsyncActionFilter
    {
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            var resultContext = await next();

            var userId = int.Parse(resultContext.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value);

            var repo = resultContext.HttpContext.RequestServices
                .GetService<IUserRepository>();

            var user = repo.GetUserById(userId);

            user.LastActive= DateTime.Now;
            await repo.SaveAll();
        }
    }
}

这是我的资料库

 public async Task<User> GetUserById(int id)
        {
            var user =await  _context.Users.Include(p=>p.Photos).FirstOrDefaultAsync(u=>u.Id==id);
            return user;
        }

1 个答案:

答案 0 :(得分:9)

conda activate my_env conda install python=3.6 不返回GetUserById,而是返回User。您需要等待它来获取Task<User>

User