C# 具有两个导航属性的Lambda表达式

C# 具有两个导航属性的Lambda表达式,c#,lambda,wcf-ria-services,C#,Lambda,Wcf Ria Services,在这种情况下,我调用一个实体,并在ria服务调用中放入两个包含项 public IQueryable<Position> GetPositions(int programID) { return _positionRepository.All() .Where(x => x.ProgramID == programID) .Include("RecPositions.Person"); } 测试现在有了我

在这种情况下,我调用一个实体,并在ria服务调用中放入两个包含项

public IQueryable<Position> GetPositions(int programID)
{
    return _positionRepository.All()
                .Where(x => x.ProgramID == programID)
                .Include("RecPositions.Person");
}

测试现在有了我的记录…但我想知道如何编写lambda express,以便获得person对象的句柄

我想到了这个..有人反对这个或更好的方法吗

var test = _allRec.SelectMany(x => x.RecPositions)
                  .Select(p => p.Person)
                  .ToList();

这似乎给了我想要的。

我猜在最终的.ToList()之前加入.Distinct()可能会对您有所帮助,但其他方面看起来不错。
var test = _allRec.SelectMany(x => x.RecPositions)
                  .Select(p => p.Person)
                  .ToList();