@@ -403,10 +403,7 @@ private void DereferenceEntity(EntityType entityType, bool implicitJoin, string
403
403
bool joinIsNeeded ;
404
404
405
405
// 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 ;
410
407
411
408
if ( IsDotNode ( parent ) )
412
409
{
@@ -415,7 +412,7 @@ private void DereferenceEntity(EntityType entityType, bool implicitJoin, string
415
412
// entity's PK (because 'our' table would know the FK).
416
413
parentAsDotNode = ( DotNode ) parent ;
417
414
property = parentAsDotNode . _propertyName ;
418
- joinIsNeeded = generateJoin && ( ( Walker . IsSelectStatement && comparisonWithNullableEntityOrThroughPropertyRef ) || ! IsReferenceToPrimaryKey ( parentAsDotNode . _propertyName , entityType ) ) ;
415
+ joinIsNeeded = generateJoin && ( ( Walker . IsSelectStatement && comparisonWithNullableEntity ) || ! IsReferenceToPrimaryKey ( parentAsDotNode . _propertyName , entityType ) ) ;
419
416
}
420
417
else if ( ! Walker . IsSelectStatement )
421
418
{
@@ -429,14 +426,19 @@ private void DereferenceEntity(EntityType entityType, bool implicitJoin, string
429
426
else
430
427
{
431
428
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 ;
433
434
}
434
435
435
436
if ( joinIsNeeded )
436
437
{
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 ;
438
440
DereferenceEntityJoin ( classAlias , entityType , implicitJoin , parent , forceLeftJoin ) ;
439
- if ( comparisonWithNullableEntityOrThroughPropertyRef )
441
+ if ( comparisonWithNullableEntity )
440
442
{
441
443
_columns = FromElement . GetIdentityColumns ( ) ;
442
444
}
0 commit comments