@@ -403,10 +403,7 @@ private void DereferenceEntity(EntityType entityType, bool implicitJoin, string
403403 bool joinIsNeeded ;
404404
405405 // For nullable entity comparisons we always need to add join (like not constrained one-to-one or not-found ignore associations).
406- // For property-ref associations, we also need this unless finding a way in the IdentNode for the other hand of the comparison
407- // 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 ) ;
406+ var comparisonWithNullableEntity = Walker . IsComparativeExpressionClause && entityType . IsNullable ;
410407
411408 if ( IsDotNode ( parent ) )
412409 {
@@ -415,7 +412,7 @@ private void DereferenceEntity(EntityType entityType, bool implicitJoin, string
415412 // entity's PK (because 'our' table would know the FK).
416413 parentAsDotNode = ( DotNode ) parent ;
417414 property = parentAsDotNode . _propertyName ;
418- joinIsNeeded = generateJoin && ( ( Walker . IsSelectStatement && comparisonWithNullableEntityOrThroughPropertyRef ) || ! IsReferenceToPrimaryKey ( parentAsDotNode . _propertyName , entityType ) ) ;
415+ joinIsNeeded = generateJoin && ( ( Walker . IsSelectStatement && comparisonWithNullableEntity ) || ! IsReferenceToPrimaryKey ( parentAsDotNode . _propertyName , entityType ) ) ;
419416 }
420417 else if ( ! Walker . IsSelectStatement )
421418 {
@@ -429,14 +426,19 @@ private void DereferenceEntity(EntityType entityType, bool implicitJoin, string
429426 else
430427 {
431428 joinIsNeeded = generateJoin || ( Walker . IsInSelect && ! Walker . IsInCase ) || ( Walker . IsInFrom && ! Walker . IsComparativeExpressionClause )
432- || comparisonWithNullableEntityOrThroughPropertyRef ;
429+ || comparisonWithNullableEntity
430+ // For property-ref association comparison, we also need to join unless finding a way in the node for the other hand of the comparison
431+ // to detect it should yield the property-ref columns instead of the primary key columns. And if the other hand is an association too,
432+ // it may be a reference to the primary key, so we would need to join anyway.
433+ || Walker . IsComparativeExpressionClause && ! entityType . IsReferenceToPrimaryKey ;
433434 }
434435
435436 if ( joinIsNeeded )
436437 {
437- var forceLeftJoin = comparisonWithNullableEntityOrThroughPropertyRef && ! IsCorrelatedSubselect ;
438+ // Subselect queries use theta style joins, which cannot be forced to left outer joins.
439+ var forceLeftJoin = comparisonWithNullableEntity && ! IsCorrelatedSubselect ;
438440 DereferenceEntityJoin ( classAlias , entityType , implicitJoin , parent , forceLeftJoin ) ;
439- if ( comparisonWithNullableEntityOrThroughPropertyRef )
441+ if ( comparisonWithNullableEntity )
440442 {
441443 _columns = FromElement . GetIdentityColumns ( ) ;
442444 }
0 commit comments