2015-09-11 87 views
0

我有這樣的LINQ表達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是一個對象而不是列表。

+1

是'goal'集合? –

+0

對我來說很好。你確定有一個與該目標相關的教育計劃嗎? –

回答

1

對於多層次的,你應該是這樣的:

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

是什麼讓你認爲'Goal'是一個集合? – juharr

+0

但目標不是一個列表,是一個對象,thx – Malinosqui

+0

不工作兩個,這很奇怪 – Malinosqui