我仍然與此鬥爭,爲什麼每個'類別'項目返回空'任務'集合。我確實有數據庫中的數據,我錯過了什麼?查詢不返回子集合
public class ApplicationUser : IdentityUser
{
public ICollection<Category> Categories { get; set; }
}
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 IEnumerable<Category> GetAllForUser(string name)
{
return _ctx.Users.Where(x => x.UserName == name)
.SelectMany(x => x.Categories)
.Include(x => x.Tasks).ToList();
}
這是完美的伊萬,很好的解釋,我已經針對上面提到的完全理解它進行了測試,並且您已經確定瞭解決方案。我很感激 – lucas