@@ -48,6 +48,25 @@ public async Task CanJoinNotAssociatedEntityAsync()
4848 }
4949 }
5050
51+ //check JoinEntityAlias - JoinAlias analog for entity join
52+ [ Test ]
53+ public async Task CanJoinNotAssociatedEntity_ExpressionAsync ( )
54+ {
55+ using ( var sqlLog = new SqlLogSpy ( ) )
56+ using ( var session = OpenSession ( ) )
57+ {
58+ EntityComplex entityComplex = null ;
59+ EntityWithNoAssociation root = null ;
60+ root = await ( session . QueryOver ( ( ) => root )
61+ . JoinEntityAlias ( ( ) => entityComplex , ( ) => root . Complex1Id == entityComplex . Id ) . Take ( 1 )
62+ . SingleOrDefaultAsync ( ) ) ;
63+ entityComplex = await ( session . LoadAsync < EntityComplex > ( root . Complex1Id ) ) ;
64+
65+ Assert . That ( NHibernateUtil . IsInitialized ( entityComplex ) , Is . True ) ;
66+ Assert . That ( sqlLog . Appender . GetEvents ( ) . Length , Is . EqualTo ( 1 ) , "Only one SQL select is expected" ) ;
67+ }
68+ }
69+
5170 //check JoinEntityQueryOver - JoinQueryOver analog for entity join
5271 [ Test ]
5372 public async Task CanJoinEntityQueryOverAsync ( )
@@ -254,6 +273,61 @@ public async Task EntityJoinForCustomEntityNameAsync()
254273 }
255274 }
256275
276+ [ Test ]
277+ public async Task EntityJoinFoSubquery_JoinEntityAliasAsync ( )
278+ {
279+ using ( var sqlLog = new SqlLogSpy ( ) )
280+ using ( var session = OpenSession ( ) )
281+ {
282+ EntityComplex ej = null ;
283+ EntityWithNoAssociation root = null ;
284+
285+ EntityComplex ejSub = null ;
286+ EntityWithNoAssociation rootSub = null ;
287+
288+ var subquery = QueryOver . Of < EntityWithNoAssociation > ( ( ) => rootSub )
289+ . JoinEntityAlias ( ( ) => ejSub , ( ) => rootSub . Complex1Id == ejSub . Id )
290+ . Where ( r => ejSub . Name == ej . Name )
291+ . Select ( x => ejSub . Id ) ;
292+
293+ root = await ( session . QueryOver ( ( ) => root )
294+ . JoinEntityAlias ( ( ) => ej , Restrictions . Where ( ( ) => root . Complex1Id == ej . Id ) )
295+ . WithSubquery . WhereExists ( subquery )
296+ . SingleOrDefaultAsync ( ) ) ;
297+ ej = await ( session . LoadAsync < EntityComplex > ( root . Complex1Id ) ) ;
298+
299+ Assert . That ( NHibernateUtil . IsInitialized ( ej ) , Is . True ) ;
300+ Assert . That ( sqlLog . Appender . GetEvents ( ) . Length , Is . EqualTo ( 1 ) , "Only one SQL select is expected" ) ;
301+ }
302+ }
303+
304+ [ Test ]
305+ public async Task EntityJoinFoSubquery_JoinQueryOverAsync ( )
306+ {
307+ using ( var sqlLog = new SqlLogSpy ( ) )
308+ using ( var session = OpenSession ( ) )
309+ {
310+ EntityComplex ej = null ;
311+ EntityWithNoAssociation root = null ;
312+
313+ EntityComplex ejSub = null ;
314+ EntityWithNoAssociation rootSub = null ;
315+
316+ var subquery = QueryOver . Of < EntityWithNoAssociation > ( ( ) => rootSub )
317+ . JoinEntityQueryOver ( ( ) => ejSub , ( ) => rootSub . Complex1Id == ejSub . Id )
318+ . Where ( x => x . Name == ej . Name )
319+ . Select ( x => ejSub . Id ) ;
320+
321+ root = await ( session . QueryOver ( ( ) => root )
322+ . JoinEntityAlias ( ( ) => ej , Restrictions . Where ( ( ) => root . Complex1Id == ej . Id ) )
323+ . WithSubquery . WhereExists ( subquery )
324+ . SingleOrDefaultAsync ( ) ) ;
325+ ej = await ( session . LoadAsync < EntityComplex > ( root . Complex1Id ) ) ;
326+
327+ Assert . That ( NHibernateUtil . IsInitialized ( ej ) , Is . True ) ;
328+ Assert . That ( sqlLog . Appender . GetEvents ( ) . Length , Is . EqualTo ( 1 ) , "Only one SQL select is expected" ) ;
329+ }
330+ }
257331 #region Test Setup
258332
259333 protected override HbmMapping GetMappings ( )
0 commit comments