Skip to content

Commit 7c31eb5

Browse files
committed
Fix
1 parent 849b031 commit 7c31eb5

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/NHibernate/Loader/JoinWalker.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,6 @@ private void WalkCollectionTree(IQueryableCollection persister, string alias, st
347347
string[] aliasedLhsColumns = persister.GetElementColumnNames(alias);
348348
string[] lhsColumns = persister.ElementColumnNames;
349349

350-
// if the current depth is 0, the root thing being loaded is the
351-
// many-to-many collection itself. Here, it is alright to use
352-
// an inner join...
353-
bool useInnerJoin = _depth == 0;
354-
355350
var joinType =
356351
GetJoinType(
357352
associationType,
@@ -360,10 +355,16 @@ private void WalkCollectionTree(IQueryableCollection persister, string alias, st
360355
pathAlias,
361356
persister.TableName,
362357
lhsColumns,
363-
!useInnerJoin,
358+
false,
364359
_depth - 1,
365360
null);
366361

362+
// It's safe to always use inner join for many-to-many not-found ignore mapping as it's processed by table group join;
363+
// otherwise we need left join for proper not-found exception handling
364+
if (joinType == JoinType.LeftOuterJoin && ((EntityType) type).IsNullable)
365+
joinType = JoinType.InnerJoin;
366+
367+
367368
AddAssociationToJoinTreeIfNecessary(
368369
associationType,
369370
aliasedLhsColumns,

0 commit comments

Comments
 (0)