Skip to content

Commit 5e4ab3c

Browse files
Improve the fix attempt
1 parent b1cf002 commit 5e4ab3c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/NHibernate/Hql/Ast/ANTLR/Tree/DotNode.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,7 @@ private void DereferenceEntity(EntityType entityType, bool implicitJoin, string
405405
// For nullable entity comparisons we always need to add join (like not constrained one-to-one or not-found ignore associations).
406406
// For property-ref associations, we also need this unless finding a way in the IdentNode for the other hand of the comparison
407407
// to detect it should yield the property-ref columns instead of the primary key columns.
408-
bool comparisonWithNullableEntityOrThroughPropertyRef = Walker.IsComparativeExpressionClause
409-
&& (entityType.IsNullable || entityType.IsUniqueKeyReference);
408+
var comparisonWithNullableEntity = Walker.IsComparativeExpressionClause && entityType.IsNullable;
410409

411410
if ( IsDotNode( parent ) )
412411
{
@@ -415,7 +414,7 @@ private void DereferenceEntity(EntityType entityType, bool implicitJoin, string
415414
// entity's PK (because 'our' table would know the FK).
416415
parentAsDotNode = ( DotNode ) parent;
417416
property = parentAsDotNode._propertyName;
418-
joinIsNeeded = generateJoin && ((Walker.IsSelectStatement && comparisonWithNullableEntityOrThroughPropertyRef) || !IsReferenceToPrimaryKey( parentAsDotNode._propertyName, entityType ));
417+
joinIsNeeded = generateJoin && ((Walker.IsSelectStatement && comparisonWithNullableEntity) || !IsReferenceToPrimaryKey( parentAsDotNode._propertyName, entityType ));
419418
}
420419
else if ( ! Walker.IsSelectStatement )
421420
{
@@ -429,14 +428,15 @@ private void DereferenceEntity(EntityType entityType, bool implicitJoin, string
429428
else
430429
{
431430
joinIsNeeded = generateJoin || (Walker.IsInSelect && !Walker.IsInCase) || (Walker.IsInFrom && !Walker.IsComparativeExpressionClause)
432-
|| comparisonWithNullableEntityOrThroughPropertyRef;
431+
|| comparisonWithNullableEntity || !entityType.IsReferenceToPrimaryKey;
433432
}
434433

435434
if ( joinIsNeeded )
436435
{
437-
var forceLeftJoin = comparisonWithNullableEntityOrThroughPropertyRef && !IsCorrelatedSubselect;
436+
// Subselect queries use theta style joins, which cannot be forced to left outer joins.
437+
var forceLeftJoin = comparisonWithNullableEntity && !IsCorrelatedSubselect;
438438
DereferenceEntityJoin(classAlias, entityType, implicitJoin, parent, forceLeftJoin);
439-
if (comparisonWithNullableEntityOrThroughPropertyRef)
439+
if (comparisonWithNullableEntity)
440440
{
441441
_columns = FromElement.GetIdentityColumns();
442442
}

0 commit comments

Comments
 (0)