错误:无法隐式转换类型List <icollection <category>&gt;列出<category>

时间:2016-08-08 20:29:19

标签: entity-framework linq

如何解决此转化问题?查询生成正确的结果,但不能返回List

public class Category
{
    public int CategoryId { get; set; }
    public string Name { get; set; }
    public DateTime Timestamp { get; set; }


    public ICollection<Task> Tasks { get; set; }
}

public class Task
{
    public int TaskId { get; set; }
    public string Name { get; set; }
    public DateTime Timestamp { get; set; }
}

public class ApplicationUser : IdentityUser
{
    public ICollection<Category> Categories { get; set; }
}

导致问题的代码:

    public List<Category> GetAllForUser(string name)
    {
        return _ctx.Users
                .Include(x => x.Categories)
                .ThenInclude(x => x.Tasks)
                .Where(x => x.UserName == "val")
                .Select(x => x.Categories).ToList();

0 个答案:

没有答案