C# 什么';此EF Join方法调用有何问题?

C# 什么';此EF Join方法调用有何问题?,c#,linq,entity-framework-4,C#,Linq,Entity Framework 4,我目前仅限于在EF4数据存储库上使用扩展方法;我不能用linq来EF。我正在尝试使一个简单的3表联接工作。代码如下: var query = _readOnlyRepository.All<Parent>() .Where( p => p.Something == "something" ) .Join( _readOnlyRepository.All<Child>(), // Child entity

我目前仅限于在EF4数据存储库上使用扩展方法;我不能用linq来EF。我正在尝试使一个简单的3表联接工作。代码如下:

var query = _readOnlyRepository.All<Parent>()
            .Where( p => p.Something == "something" )
            .Join( _readOnlyRepository.All<Child>(), // Child entity
                p => p.ParentID,                     // Parent Key
                c => c.ChildId,                      // Child Key
                ( p, c ) => c )                      // Projection
            .Join( _readOnlyRepository.All<GrandChild>(),
                c => m.ChildID,
                g => g.GrandChildID,
                ( c, g ) => g )
            .Select( joined => joined.Child.Whatever );  

我可以在代码中更改什么来消除使查询意图无效的左外连接?

我不清楚您正试图返回什么-孙子的Whatever属性?您的第二个连接返回孙子对象
(c,g)=>g
,因此我认为您只需要

.Select( joined => joined.Whatever );   

因为这里的
joined
是孙子对象。

据我所知,“joined”是父对象和连接的子对象;筛选Where()后第一次调用All()的结果。这就是我加入的原因。孩子。随便什么。智能感知同意;它有父属性,而不是孙子属性。我认为最终的结果是父对象,而不是上一次连接的结果。我当时正在访问join.Child,我以为我将成为父母->孩子,但实际上,这个属性是相反的:孙子->孩子。修复方法是将(c,g)=>g更改为(c,g)=>c,以返回孩子而不是孙子。
.Select( joined => joined.Whatever );