Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Linq包括不工作_C#_Linq_Lambda - Fatal编程技术网

C# Linq包括不工作

C# Linq包括不工作,c#,linq,lambda,C#,Linq,Lambda,我有这个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.

我有这个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();
教育计划的纳入不起作用,为什么?所有其他工作正常,
教育计划是一个对象而不是一个列表。

对于多个级别,您应该这样做:

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();

goal
是收藏吗?我觉得不错。你确定有与该目标相关联的教育计划吗?是什么让你认为
goal
是一个集合?这个.Include(“goal.EducationalPlan”)应该有效!