@@ -122,6 +122,10 @@ private FromElement CreateFromElementInSubselect(
122
122
123
123
string tableAlias = correlatedSubselect ? fromElement . TableAlias : null ;
124
124
125
+ //To properly generete subselect implicit join is required by SqlGenerator
126
+ if ( fromElement . IsImplied )
127
+ fromElement . JoinSequence . SetUseThetaStyle ( true ) ;
128
+
125
129
// If the from element isn't in the same clause, create a new from element.
126
130
if ( fromElement . FromClause != _fromClause )
127
131
{
@@ -189,18 +193,18 @@ public FromElement CreateCollection(IQueryableCollection queryableCollection,
189
193
if ( elementType . IsEntityType )
190
194
{
191
195
// A collection of entities...
192
- elem = CreateEntityAssociation ( role , roleAlias , joinType ) ;
196
+ elem = CreateEntityAssociation ( role , roleAlias , joinType , indexed ) ;
193
197
}
194
198
else if ( elementType . IsComponentType )
195
199
{
196
200
// A collection of components...
197
- JoinSequence joinSequence = CreateJoinSequence ( roleAlias , joinType ) ;
201
+ JoinSequence joinSequence = CreateJoinSequence ( roleAlias , joinType , indexed ) ;
198
202
elem = CreateCollectionJoin ( joinSequence , roleAlias ) ;
199
203
}
200
204
else
201
205
{
202
206
// A collection of scalar elements...
203
- JoinSequence joinSequence = CreateJoinSequence ( roleAlias , joinType ) ;
207
+ JoinSequence joinSequence = CreateJoinSequence ( roleAlias , joinType , indexed ) ;
204
208
elem = CreateCollectionJoin ( joinSequence , roleAlias ) ;
205
209
}
206
210
@@ -332,7 +336,8 @@ public FromElement CreateEntityJoin(
332
336
private FromElement CreateEntityAssociation (
333
337
string role ,
334
338
string roleAlias ,
335
- JoinType joinType )
339
+ JoinType joinType ,
340
+ bool implicitJoin )
336
341
{
337
342
FromElement elem ;
338
343
IQueryable entityPersister = ( IQueryable ) _queryableCollection . ElementPersister ;
@@ -346,7 +351,7 @@ private FromElement CreateEntityAssociation(
346
351
Log . Debug ( "createEntityAssociation() : One to many - path = {0} role = {1} associatedEntityName = {2}" , _path , role , associatedEntityName ) ;
347
352
}
348
353
349
- var joinSequence = CreateJoinSequence ( roleAlias , joinType ) ;
354
+ var joinSequence = CreateJoinSequence ( roleAlias , joinType , implicitJoin ) ;
350
355
351
356
elem = CreateJoin ( associatedEntityName , roleAlias , joinSequence , ( EntityType ) _queryableCollection . ElementType , false ) ;
352
357
elem . UseFromFragment |= elem . IsImplied && elem . Walker . IsSubQuery ;
@@ -358,7 +363,7 @@ private FromElement CreateEntityAssociation(
358
363
Log . Debug ( "createManyToMany() : path = {0} role = {1} associatedEntityName = {2}" , _path , role , associatedEntityName ) ;
359
364
}
360
365
361
- elem = CreateManyToMany ( role , associatedEntityName , roleAlias , entityPersister , ( EntityType ) _queryableCollection . ElementType , joinType ) ;
366
+ elem = CreateManyToMany ( role , associatedEntityName , roleAlias , entityPersister , ( EntityType ) _queryableCollection . ElementType , joinType , implicitJoin ) ;
362
367
_fromClause . Walker . AddQuerySpaces ( _queryableCollection ) ;
363
368
}
364
369
elem . CollectionTableAlias = roleAlias ;
@@ -401,15 +406,16 @@ private FromElement CreateManyToMany(
401
406
string roleAlias ,
402
407
IEntityPersister entityPersister ,
403
408
EntityType type ,
404
- JoinType joinType )
409
+ JoinType joinType ,
410
+ bool implicitJoin )
405
411
{
406
412
FromElement elem ;
407
413
SessionFactoryHelperExtensions sfh = _fromClause . SessionFactoryHelper ;
408
414
409
415
if ( _inElementsFunction /*implied*/ )
410
416
{
411
417
// For implied many-to-many, just add the end join.
412
- JoinSequence joinSequence = CreateJoinSequence ( roleAlias , joinType ) ;
418
+ JoinSequence joinSequence = CreateJoinSequence ( roleAlias , joinType , implicitJoin ) ;
413
419
elem = CreateJoin ( associatedEntityName , roleAlias , joinSequence , type , true ) ;
414
420
}
415
421
else
@@ -421,23 +427,24 @@ private FromElement CreateManyToMany(
421
427
string [ ] secondJoinColumns = sfh . GetCollectionElementColumns ( role , roleAlias ) ;
422
428
423
429
// Add the second join, the one that ends in the destination table.
424
- JoinSequence joinSequence = CreateJoinSequence ( roleAlias , joinType ) ;
430
+ JoinSequence joinSequence = CreateJoinSequence ( roleAlias , joinType , implicitJoin ) ;
425
431
joinSequence . AddJoin ( sfh . GetElementAssociationType ( _collectionType ) , tableAlias , joinType , secondJoinColumns ) ;
426
432
elem = CreateJoin ( associatedEntityName , tableAlias , joinSequence , type , false ) ;
427
433
elem . UseFromFragment = true ;
428
434
}
429
435
return elem ;
430
436
}
431
437
432
- private JoinSequence CreateJoinSequence ( string roleAlias , JoinType joinType )
438
+ //TODO: Investigate why not implicit indexed collection join is incorrectly generated and get rid of implicitJoin parameter (check IndexNode.Resolve)
439
+ private JoinSequence CreateJoinSequence ( string roleAlias , JoinType joinType , bool implicitJoin )
433
440
{
434
441
SessionFactoryHelperExtensions sessionFactoryHelper = _fromClause . SessionFactoryHelper ;
435
442
string [ ] joinColumns = Columns ;
436
443
if ( _collectionType == null )
437
444
{
438
445
throw new InvalidOperationException ( "collectionType is null!" ) ;
439
446
}
440
- return sessionFactoryHelper . CreateJoinSequence ( _implied , _collectionType , roleAlias , joinType , joinColumns ) ;
447
+ return sessionFactoryHelper . CreateJoinSequence ( implicitJoin , _collectionType , roleAlias , joinType , joinColumns ) ;
441
448
}
442
449
443
450
private FromElement CreateJoin (
0 commit comments