我有这样的问题
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 提供程序中的错误吗?也许有解决方法?
最佳答案
Added issue在休眠 jira 上
关于c# - LINQ to Nhibernate 重复连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8152298/