@@ -123,8 +123,10 @@ public void SelectModeFetchLazyProperties()
123
123
124
124
125
125
[ Test ]
126
- public void SelectModeChildFetchForMultipleCollections ( )
126
+ public void SelectModeChildFetchForMultipleCollections_SingleDbRoundtrip ( )
127
127
{
128
+ SkipFutureTestIfNotSupported ( ) ;
129
+
128
130
using ( var sqlLog = new SqlLogSpy ( ) )
129
131
using ( var session = OpenSession ( ) )
130
132
{
@@ -161,6 +163,41 @@ public void SelectModeChildFetchForMultipleCollections()
161
163
}
162
164
}
163
165
166
+ [ Test ]
167
+ public void SelectModeChildFetchForMultipleCollections ( )
168
+ {
169
+ using ( var session = OpenSession ( ) )
170
+ {
171
+ EntityComplex root = null ;
172
+ root = session
173
+ . QueryOver ( ( ) => root )
174
+ . Where ( r => r . Id == _parentEntityComplexId )
175
+ . SingleOrDefault ( ) ;
176
+
177
+ session
178
+ . QueryOver ( ( ) => root )
179
+ //Only ID is added to SELECT statement for root so it's index scan only
180
+ . With ( SelectMode . ChildFetch , ec => ec )
181
+ . With ( SelectMode . Fetch , ec => ec . ChildrenList )
182
+ . Where ( r => r . Id == _parentEntityComplexId )
183
+ . List ( ) ;
184
+
185
+ session
186
+ . QueryOver ( ( ) => root )
187
+ . With ( SelectMode . ChildFetch , ec => ec )
188
+ . With ( SelectMode . Fetch , ec => ec . ChildrenListEmpty )
189
+ . Where ( r => r . Id == _parentEntityComplexId )
190
+ . List ( ) ;
191
+
192
+ Assert . That ( root ? . ChildrenList , Is . Not . Null ) ;
193
+ Assert . That ( root ? . ChildrenListEmpty , Is . Not . Null ) ;
194
+ Assert . That ( NHibernateUtil . IsInitialized ( root ? . ChildrenList ) , "ChildrenList must be initialized" ) ;
195
+ Assert . That ( NHibernateUtil . IsInitialized ( root ? . ChildrenListEmpty ) , "ChildrenListEmpty must be initialized" ) ;
196
+ Assert . That ( root ? . ChildrenList , Is . Not . Empty , "ChildrenList must not be empty" ) ;
197
+ Assert . That ( root ? . ChildrenListEmpty , Is . Empty , "ChildrenListEmpty must be empty" ) ;
198
+ }
199
+ }
200
+
164
201
[ Test ]
165
202
public void SelectModeSkipEntityJoin ( )
166
203
{
@@ -187,7 +224,7 @@ public void SelectModeSkipEntityJoin()
187
224
188
225
189
226
[ Test ]
190
- public void SelectModeFetchLazyPropertiesForEntityAlias ( )
227
+ public void SelectModeFetchLazyPropertiesForEntityJoin ( )
191
228
{
192
229
using ( var sqlLog = new SqlLogSpy ( ) )
193
230
using ( var session = OpenSession ( ) )
@@ -235,12 +272,15 @@ public void SelectModeChildFetchReturnsNullForNotLoadedObjectAndDoesntThrowExcep
235
272
[ Test ]
236
273
public void SelectModeChildFetchDeep_SingleDbRoundtrip_Aliased ( )
237
274
{
275
+ SkipFutureTestIfNotSupported ( ) ;
276
+
238
277
using ( var sqlLog = new SqlLogSpy ( ) )
239
278
using ( var session = OpenSession ( ) )
240
279
{
241
280
EntityComplex root = null ;
242
- var rootFuture = session . QueryOver ( ( ) => root )
243
- . Future ( ) ;
281
+ var rootFuture = session
282
+ . QueryOver ( ( ) => root )
283
+ . Future ( ) ;
244
284
245
285
session
246
286
. QueryOver ( ( ) => root )
@@ -271,7 +311,45 @@ public void SelectModeChildFetchDeep_SingleDbRoundtrip_Aliased()
271
311
Assert . That ( sqlLog . Appender . GetEvents ( ) . Length , Is . EqualTo ( 1 ) , "Only one SQL select is expected" ) ;
272
312
}
273
313
}
314
+
315
+ [ Test ]
316
+ public void SelectModeChildFetchDeep_Aliased ( )
317
+ {
318
+ using ( var session = OpenSession ( ) )
319
+ {
320
+ EntityComplex root = null ;
321
+ var list = session
322
+ . QueryOver ( ( ) => root )
323
+ . List ( ) ;
274
324
325
+ session
326
+ . QueryOver ( ( ) => root )
327
+ . With ( SelectMode . ChildFetch , ( ) => root )
328
+ . With ( SelectMode . Fetch , ( ) => root . ChildrenList )
329
+ . List ( ) ;
330
+
331
+ session
332
+ . QueryOver ( ( ) => root )
333
+ . With ( SelectMode . ChildFetch , ( ) => root , ( ) => root . ChildrenList )
334
+ . With ( SelectMode . Fetch , ( ) => root . ChildrenList [ 0 ] . Children )
335
+ . List ( ) ;
336
+
337
+ session
338
+ . QueryOver ( ( ) => root )
339
+ . With ( SelectMode . Skip , ( ) => root . ChildrenList )
340
+ . With ( SelectMode . ChildFetch , ( ) => root , ( ) => root . ChildrenList [ 0 ] . Children )
341
+ . With ( SelectMode . Fetch , ( ) => root . ChildrenList [ 0 ] . Children [ 0 ] . Children )
342
+ . List ( ) ;
343
+
344
+ root = list . First ( r => r . Id == _parentEntityComplexId ) ;
345
+
346
+
347
+ Assert . That ( root ? . ChildrenList , Is . Not . Null ) ;
348
+ Assert . That ( NHibernateUtil . IsInitialized ( root ? . ChildrenList ) ) ;
349
+ Assert . That ( NHibernateUtil . IsInitialized ( root ? . ChildrenList [ 0 ] . Children ) ) ;
350
+ Assert . That ( NHibernateUtil . IsInitialized ( root ? . ChildrenList [ 0 ] . Children [ 0 ] . Children ) ) ;
351
+ }
352
+ }
275
353
276
354
[ Test ]
277
355
public void SkipRootEntityIsNotSupported ( )
@@ -288,6 +366,13 @@ public void SkipRootEntityIsNotSupported()
288
366
}
289
367
}
290
368
369
+ private void SkipFutureTestIfNotSupported ( )
370
+ {
371
+ var driver = Sfi . ConnectionProvider . Driver ;
372
+ if ( driver . SupportsMultipleQueries == false )
373
+ Assert . Ignore ( "Driver {0} does not support multi-queries" , driver . GetType ( ) . FullName ) ;
374
+ }
375
+
291
376
#region Test Setup
292
377
293
378
protected override HbmMapping GetMappings ( )
0 commit comments