【发布时间】:2014-01-15 01:11:30
【问题描述】:
我有这样的查询
var orderedQueryable = this.participationRequests
.Fetch(x => x.CommunityEvent)
.Fetch(x => x.CommunityMember)
.ThenFetch(x => x.User)
.Where(x => x.CommunityMember.Community.Id == communityId)
.OrderBy(x => x.CreateDate);
由于this bug,where 子句需要在 fetch 之后。
问题是 thouse Fetch 调用会发出额外的连接。在 SQL 中查询如下所示:
select *
from ParticipationRequests participat0_
left outer join CommunityEvents communitye1_
on participat0_.CommunityEventId = communitye1_.Id
left outer join CommunityMembers communitym2_
on participat0_.CommunityMemberId = communitym2_.Id
left outer join Users user3_
on communitym2_.UserId = user3_.Id
inner join CommunityMembers communitym4_
on participat0_.CommunityMemberId = communitym4_.Id
inner join CommunityMembers communitym5_
on participat0_.CommunityMemberId = communitym5_.Id
inner join Communities community6_
on communitym5_.CommunityId = community6_.Id
where community6_.Id = 2002 /* @p0 */
order by participat0_.CreateDate asc
它执行内连接以在CommunityId 上设置条件,并执行左外连接以进行获取。
我找到了similar question,但我的查询有不同的执行计划,有和没有额外的连接。
这是 LINQ 提供程序中的错误吗?也许有解决方法?
【问题讨论】:
标签: c# .net linq nhibernate linq-to-nhibernate