@@ -405,8 +405,7 @@ private void DereferenceEntity(EntityType entityType, bool implicitJoin, string
405
405
// For nullable entity comparisons we always need to add join (like not constrained one-to-one or not-found ignore associations).
406
406
// For property-ref associations, we also need this unless finding a way in the IdentNode for the other hand of the comparison
407
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 ) ;
408
+ var comparisonWithNullableEntity = Walker . IsComparativeExpressionClause && entityType . IsNullable ;
410
409
411
410
if ( IsDotNode ( parent ) )
412
411
{
@@ -415,7 +414,7 @@ private void DereferenceEntity(EntityType entityType, bool implicitJoin, string
415
414
// entity's PK (because 'our' table would know the FK).
416
415
parentAsDotNode = ( DotNode ) parent ;
417
416
property = parentAsDotNode . _propertyName ;
418
- joinIsNeeded = generateJoin && ( ( Walker . IsSelectStatement && comparisonWithNullableEntityOrThroughPropertyRef ) || ! IsReferenceToPrimaryKey ( parentAsDotNode . _propertyName , entityType ) ) ;
417
+ joinIsNeeded = generateJoin && ( ( Walker . IsSelectStatement && comparisonWithNullableEntity ) || ! IsReferenceToPrimaryKey ( parentAsDotNode . _propertyName , entityType ) ) ;
419
418
}
420
419
else if ( ! Walker . IsSelectStatement )
421
420
{
@@ -429,14 +428,15 @@ private void DereferenceEntity(EntityType entityType, bool implicitJoin, string
429
428
else
430
429
{
431
430
joinIsNeeded = generateJoin || ( Walker . IsInSelect && ! Walker . IsInCase ) || ( Walker . IsInFrom && ! Walker . IsComparativeExpressionClause )
432
- || comparisonWithNullableEntityOrThroughPropertyRef ;
431
+ || comparisonWithNullableEntity || ! entityType . IsReferenceToPrimaryKey ;
433
432
}
434
433
435
434
if ( joinIsNeeded )
436
435
{
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 ;
438
438
DereferenceEntityJoin ( classAlias , entityType , implicitJoin , parent , forceLeftJoin ) ;
439
- if ( comparisonWithNullableEntityOrThroughPropertyRef )
439
+ if ( comparisonWithNullableEntity )
440
440
{
441
441
_columns = FromElement . GetIdentityColumns ( ) ;
442
442
}
0 commit comments