私はこのようなクエリを持っています重複する結合をNhibernateするLINQ
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);
where節はthis bugのためにフェッチした後にする必要があります。 Fetch
問題は、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プロバイダのバグですか?おそらく回避策がありますか?