@@ -209,6 +209,75 @@ public async Task SameCollectionFetchesAsync()
209
209
}
210
210
}
211
211
212
+ //NH-3864 - Cacheable Multicriteria/Future'd query with aliased join throw exception
213
+ [ Test ]
214
+ public void CacheableCriteriaWithAliasedJoinFutureAsync ( )
215
+ {
216
+ using ( var session = OpenSession ( ) )
217
+ {
218
+ EntitySimpleChild child1 = null ;
219
+ var ecFuture = session . QueryOver < EntityComplex > ( )
220
+ . JoinAlias ( c => c . Child1 , ( ) => child1 )
221
+ . Where ( c => c . Id == _parentId )
222
+ . Cacheable ( )
223
+ . FutureValue ( ) ;
224
+ EntityComplex value = null ;
225
+ Assert . DoesNotThrowAsync ( async ( ) => value = await ( ecFuture . GetValueAsync ( ) ) ) ;
226
+ Assert . That ( value , Is . Not . Null ) ;
227
+ }
228
+
229
+ using ( var sqlLog = new SqlLogSpy ( ) )
230
+ using ( var session = OpenSession ( ) )
231
+ {
232
+ EntitySimpleChild child1 = null ;
233
+ var ecFuture = session . QueryOver < EntityComplex > ( )
234
+ . JoinAlias ( c => c . Child1 , ( ) => child1 )
235
+ . Where ( c => c . Id == _parentId )
236
+ . Cacheable ( )
237
+ . FutureValue ( ) ;
238
+ EntityComplex value = null ;
239
+ Assert . DoesNotThrowAsync ( async ( ) => value = await ( ecFuture . GetValueAsync ( ) ) ) ;
240
+ Assert . That ( value , Is . Not . Null ) ;
241
+
242
+ Assert . That ( sqlLog . Appender . GetEvents ( ) . Length , Is . EqualTo ( 0 ) , "Query is expected to be retrieved from cache" ) ;
243
+ }
244
+ }
245
+
246
+ //NH-3334 - 'collection is not associated with any session' upon refreshing objects from QueryOver<>().Future<>()
247
+ [ KnownBug ( "NH-3334" ) ]
248
+ [ Test ]
249
+ public async Task RefreshFutureWithEagerCollectionsAsync ( )
250
+ {
251
+ using ( var session = OpenSession ( ) )
252
+ {
253
+ var ecFutureList = session . QueryOver < EntityEager > ( ) . Future ( ) ;
254
+
255
+ foreach ( var ec in await ( ecFutureList . GetEnumerableAsync ( ) ) )
256
+ {
257
+ //trouble causes ec.ChildrenListEager with eager select mapping
258
+ Assert . DoesNotThrowAsync ( ( ) => session . RefreshAsync ( ec ) , "session.Refresh should not throw exception" ) ;
259
+ }
260
+ }
261
+ }
262
+
263
+ //Related to NH-3334. Eager mappings are not fetched by Future
264
+ [ KnownBug ( "NH-3334" ) ]
265
+ [ Test ]
266
+ public async Task FutureForEagerMappedCollectionAsync ( )
267
+ {
268
+ //Note: This behavior might be considered as feature but it's not documented.
269
+ //Quirk: if this query is also cached - results will be still eager loaded when values retrieved from cache
270
+ using ( var session = OpenSession ( ) )
271
+ {
272
+ var futureValue = session . QueryOver < EntityEager > ( ) . Where ( e => e . Id == _eagerId ) . FutureValue ( ) ;
273
+
274
+ Assert . That ( await ( futureValue . GetValueAsync ( ) ) , Is . Not . Null ) ;
275
+ Assert . That ( NHibernateUtil . IsInitialized ( await ( futureValue . GetValueAsync ( ) ) ) , Is . True ) ;
276
+ Assert . That ( NHibernateUtil . IsInitialized ( ( await ( futureValue . GetValueAsync ( ) ) ) . ChildrenListEager ) , Is . True ) ;
277
+ Assert . That ( NHibernateUtil . IsInitialized ( ( await ( futureValue . GetValueAsync ( ) ) ) . ChildrenListSubselect ) , Is . True ) ;
278
+ }
279
+ }
280
+
212
281
#region Test Setup
213
282
214
283
protected override HbmMapping GetMappings ( )
0 commit comments