@@ -80,7 +80,7 @@ protected override void AddAssociations()
80
80
foreach ( var entityJoinInfo in translator . GetEntityJoins ( ) . Values )
81
81
{
82
82
var tableAlias = translator . GetSQLAlias ( entityJoinInfo . Criteria ) ;
83
- var criteriaPath = entityJoinInfo . Criteria . Alias ; //path for entity join is equal to alias
83
+ var criteriaPath = entityJoinInfo . Criteria . Alias ;
84
84
var persister = entityJoinInfo . Persister as IOuterJoinLoadable ;
85
85
AddExplicitEntityJoinAssociation ( persister , tableAlias , translator . GetJoinType ( criteriaPath ) , criteriaPath ) ;
86
86
IncludeInResultIfNeeded ( persister , entityJoinInfo . Criteria , tableAlias , criteriaPath ) ;
@@ -166,13 +166,20 @@ public override string Comment
166
166
get { return "criteria query" ; }
167
167
}
168
168
169
- protected override JoinType GetJoinType ( IAssociationType type , FetchMode config , string path , string lhsTable ,
170
- string [ ] lhsColumns , bool nullable , int currentDepth ,
171
- CascadeStyle cascadeStyle )
169
+ protected override IList < string > AliasByPath ( string path , string sqlAlias )
172
170
{
173
- if ( translator . IsJoin ( path ) )
171
+ var alias = translator . AliasByPath ( path , sqlAlias ) ;
172
+ if ( alias . Count == 0 )
173
+ return base . AliasByPath ( path , sqlAlias ) ;
174
+ return alias ;
175
+ }
176
+
177
+ protected override JoinType GetJoinType ( IAssociationType type , FetchMode config , string path , string pathAlias ,
178
+ string lhsTable , string [ ] lhsColumns , bool nullable , int currentDepth , CascadeStyle cascadeStyle )
179
+ {
180
+ if ( translator . IsJoin ( path , pathAlias ) )
174
181
{
175
- return translator . GetJoinType ( path ) ;
182
+ return translator . GetJoinType ( path , pathAlias ) ;
176
183
}
177
184
178
185
if ( translator . HasProjection )
@@ -184,7 +191,7 @@ protected override JoinType GetJoinType(IAssociationType type, FetchMode config,
184
191
switch ( selectMode )
185
192
{
186
193
case SelectMode . Undefined :
187
- return base . GetJoinType ( type , config , path , lhsTable , lhsColumns , nullable , currentDepth , cascadeStyle ) ;
194
+ return base . GetJoinType ( type , config , path , pathAlias , lhsTable , lhsColumns , nullable , currentDepth , cascadeStyle ) ;
188
195
189
196
case SelectMode . Fetch :
190
197
case SelectMode . FetchLazyProperties :
@@ -200,7 +207,7 @@ protected override JoinType GetJoinType(IAssociationType type, FetchMode config,
200
207
}
201
208
}
202
209
203
- protected override string GenerateTableAlias ( int n , string path , IJoinable joinable )
210
+ protected override string GenerateTableAlias ( int n , string path , string pathAlias , IJoinable joinable )
204
211
{
205
212
// TODO: deal with side-effects (changes to includeInSelectList, userAliasList, resultTypeList)!!!
206
213
@@ -225,14 +232,14 @@ protected override string GenerateTableAlias(int n, string path, IJoinable joina
225
232
226
233
if ( shouldCreateUserAlias )
227
234
{
228
- ICriteria subcriteria = translator . GetCriteria ( path ) ;
235
+ ICriteria subcriteria = translator . GetCriteria ( path , pathAlias ) ;
229
236
sqlAlias = subcriteria == null ? null : translator . GetSQLAlias ( subcriteria ) ;
230
237
231
238
IncludeInResultIfNeeded ( joinable , subcriteria , sqlAlias , path ) ;
232
239
}
233
240
234
241
if ( sqlAlias == null )
235
- sqlAlias = base . GenerateTableAlias ( n + translator . SQLAliasCount , path , joinable ) ;
242
+ sqlAlias = base . GenerateTableAlias ( n + translator . SQLAliasCount , path , pathAlias , joinable ) ;
236
243
237
244
return sqlAlias ;
238
245
}
@@ -261,9 +268,9 @@ protected override string GenerateRootAlias(string tableName)
261
268
// NH: really not used (we are using a different ctor to support SubQueryCriteria)
262
269
}
263
270
264
- protected override SqlString GetWithClause ( string path )
271
+ protected override SqlString GetWithClause ( string path , string pathAlias )
265
272
{
266
- return translator . GetWithClause ( path ) ;
273
+ return translator . GetWithClause ( path , pathAlias ) ;
267
274
}
268
275
}
269
276
}
0 commit comments