@@ -68,14 +68,14 @@ private static bool NeedsTableGroupJoin(IReadOnlyList<IJoin> joins, SqlString[]
68
68
69
69
foreach ( var join in joins )
70
70
{
71
- var entityPersister = GetEntityPersister ( join . Joinable , out var collection ) ;
71
+ var entityPersister = GetEntityPersister ( join . Joinable , out var isManyToMany ) ;
72
72
if ( entityPersister ? . HasSubclassJoins ( includeSubclasses && isSubclassIncluded ( join . Alias ) ) != true )
73
73
continue ;
74
74
75
75
if ( hasWithClause )
76
76
return true ;
77
77
78
- if ( collection ? . IsManyToMany != true // many-to-many keys are stored in separate table
78
+ if ( ! isManyToMany // many-to-many keys are stored in separate table
79
79
&& entityPersister . ColumnsDependOnSubclassJoins ( join . RHSColumns ) )
80
80
return true ;
81
81
}
@@ -92,14 +92,14 @@ private static SqlString GetTableGroupJoinWithClause(SqlString[] withClauseFragm
92
92
var isAssociationJoin = lhsColumns . Length > 0 ;
93
93
if ( isAssociationJoin )
94
94
{
95
- var entityPersister = GetEntityPersister ( first . Joinable , out var collection ) ;
95
+ var entityPersister = GetEntityPersister ( first . Joinable , out var isManyToMany ) ;
96
96
string rhsAlias = first . Alias ;
97
97
string [ ] rhsColumns = first . RHSColumns ;
98
98
for ( int j = 0 ; j < lhsColumns . Length ; j ++ )
99
99
{
100
100
fromFragment . Add ( lhsColumns [ j ] )
101
101
. Add ( "=" )
102
- . Add ( entityPersister == null || collection ? . IsManyToMany == true // many-to-many keys are stored in separate table
102
+ . Add ( ( entityPersister == null || isManyToMany ) // many-to-many keys are stored in separate table
103
103
? rhsAlias
104
104
: entityPersister . GenerateTableAliasForColumn ( rhsAlias , rhsColumns [ j ] ) )
105
105
. Add ( "." )
@@ -114,13 +114,14 @@ private static SqlString GetTableGroupJoinWithClause(SqlString[] withClauseFragm
114
114
return fromFragment . ToSqlString ( ) ;
115
115
}
116
116
117
- private static AbstractEntityPersister GetEntityPersister ( IJoinable joinable , out IQueryableCollection collection )
117
+ private static AbstractEntityPersister GetEntityPersister ( IJoinable joinable , out bool isManyToMany )
118
118
{
119
- collection = null ;
119
+ isManyToMany = false ;
120
120
if ( ! joinable . IsCollection )
121
121
return joinable as AbstractEntityPersister ;
122
122
123
- collection = ( IQueryableCollection ) joinable ;
123
+ var collection = ( IQueryableCollection ) joinable ;
124
+ isManyToMany = collection . IsManyToMany ;
124
125
return collection . ElementType . IsEntityType ? collection . ElementPersister as AbstractEntityPersister : null ;
125
126
}
126
127
0 commit comments