【发布时间】:2018-02-09 02:06:28
【问题描述】:
我在实体框架中使用以下模型创建了表
public class User
{
public int Id{ get; set; }
public string Name { get; set; }
public bool IsActive { get; set; }
public ICollection<AssigneeMonth> AssigneeMonths { get; set; }
}
public class AssigneeMonth
{
public int Id { get; set; }
public int AssigneeId { get; set; }
public Month Month { get; set; }
public User Assignee { get; set; }
}
public class ProjectAssignee
{
public int Id { get; set; }
public int ProjectId { get; set; }
public int AssigneeId { get; set; }
public bool IsActive { get; set; }
public AutomationProject Project { get; set; }
[ForeignKey("AssigneeId")]
public User User { get; set; }
}
我正在尝试使用以下代码将数据从 AssigneeMonth 获取到集合 AssigneeMonths:
var assn = dataContext.ProjectAssignees
.Where(r => r.Project.Name == project.Name && r.IsActive)
.Include(u => u.User)
.ToList();
但是上面assn 中的AssigneeMonths 集合始终为空,即使我在AssigneeMonth 中有用户的数据
我可以知道上面的代码有什么问题吗?
【问题讨论】:
标签: c# entity-framework