我有这个linq表达式
ActionPlan
.Include(x => x.Goal)
.Include(x => x.Responsibles)
.Include(x => x.Goal.EducationalPlan)
.AsNoTracking()
.Where(x => x.State == State.Active && x.Goal.State == State.Active && x.Goal.EducationalPlan.State == State.Active)
.Where(x => x.Responsibles.Any(r => r.PersonId == pes_id))
.Distinct()
.Select(x => x.Goal)
.ToList();
EducationalPlan的包含不起作用,为什么?所有其他工作正常, EducationPlan是一个不是列表的对象。
答案 0 :(得分:2)
对于多个级别,你应该这样:
ActionPlan
.Include(x => x.Goal)
.Include(x => x.Responsibles)
.Include(x => x.Goal.Select(y => y.EducationalPlan))
.AsNoTracking()
.Where(x => x.State == State.Active && x.Goal.State == State.Active && x.Goal.EducationalPlan.State == State.Active)
.Where(x => x.Responsibles.Any(r => r.PersonId == pes_id))
.Distinct()
.Select(x => x.Goal)
.ToList();
或试试这个:
ActionPlan
.Include(x => x.Goal)
.Include(x => x.Responsibles)
.Include("Goal.EducationalPlan")
.AsNoTracking()
.Where(x => x.State == State.Active && x.Goal.State == State.Active && x.Goal.EducationalPlan.State == State.Active)
.Where(x => x.Responsibles.Any(r => r.PersonId == pes_id))
.Distinct()
.Select(x => x.Goal)
.ToList();