@@ -38,8 +38,8 @@ public async Task CanJoinNotAssociatedEntityAsync()
3838 {
3939 EntityComplex entityComplex = null ;
4040 EntityWithNoAssociation root = null ;
41- root = await ( session . QueryOver < EntityWithNoAssociation > ( ( ) => root )
42- . JoinEntityAlias ( ( ) => entityComplex , Restrictions . Where ( ( ) => root . Complex1Id == entityComplex . Id ) , JoinType . InnerJoin ) . Take ( 1 )
41+ root = await ( session . QueryOver ( ( ) => root )
42+ . JoinEntityAlias ( ( ) => entityComplex , Restrictions . Where ( ( ) => root . Complex1Id == entityComplex . Id ) ) . Take ( 1 )
4343 . SingleOrDefaultAsync ( ) ) ;
4444 entityComplex = await ( session . LoadAsync < EntityComplex > ( root . Complex1Id ) ) ;
4545
@@ -76,8 +76,28 @@ public async Task CanJoinEntityQueryOverAsync()
7676 {
7777 EntityComplex ejQueryOver = null ;
7878 EntityWithNoAssociation root = null ;
79- root = await ( session . QueryOver < EntityWithNoAssociation > ( ( ) => root )
80- . JoinEntityQueryOver ( ( ) => ejQueryOver , Restrictions . Where ( ( ) => root . Complex1Id == ejQueryOver . Id ) , JoinType . InnerJoin )
79+ root = await ( session . QueryOver ( ( ) => root )
80+ . JoinEntityQueryOver ( ( ) => ejQueryOver , Restrictions . Where ( ( ) => root . Complex1Id == ejQueryOver . Id ) )
81+ . Take ( 1 )
82+ . SingleOrDefaultAsync ( ) ) ;
83+ ejQueryOver = await ( session . LoadAsync < EntityComplex > ( root . Complex1Id ) ) ;
84+
85+ Assert . That ( NHibernateUtil . IsInitialized ( ejQueryOver ) , Is . True ) ;
86+ Assert . That ( sqlLog . Appender . GetEvents ( ) . Length , Is . EqualTo ( 1 ) , "Only one SQL select is expected" ) ;
87+ }
88+ }
89+
90+ //check JoinEntityQueryOver - JoinQueryOver analog for entity join
91+ [ Test ]
92+ public async Task CanJoinEntityQueryOver_ExpressionAsync ( )
93+ {
94+ using ( var sqlLog = new SqlLogSpy ( ) )
95+ using ( var session = OpenSession ( ) )
96+ {
97+ EntityComplex ejQueryOver = null ;
98+ EntityWithNoAssociation root = null ;
99+ root = await ( session . QueryOver ( ( ) => root )
100+ . JoinEntityQueryOver ( ( ) => ejQueryOver , ( ) => root . Complex1Id == ejQueryOver . Id )
81101 . Take ( 1 )
82102 . SingleOrDefaultAsync ( ) ) ;
83103 ejQueryOver = await ( session . LoadAsync < EntityComplex > ( root . Complex1Id ) ) ;
@@ -96,8 +116,8 @@ public async Task CanQueryOverForAssociationInNotAssociatedEntityAsync()
96116 {
97117 EntityComplex ejComplex = null ;
98118 EntityWithNoAssociation root = null ;
99- root = await ( session . QueryOver < EntityWithNoAssociation > ( ( ) => root )
100- . JoinEntityQueryOver ( ( ) => ejComplex , Restrictions . Where ( ( ) => root . Complex1Id == ejComplex . Id ) , JoinType . InnerJoin )
119+ root = await ( session . QueryOver ( ( ) => root )
120+ . JoinEntityQueryOver ( ( ) => ejComplex , ( ) => root . Complex1Id == ejComplex . Id )
101121 . JoinQueryOver ( ej => ej . Child1 )
102122 . Take ( 1 )
103123 . SingleOrDefaultAsync ( ) ) ;
@@ -119,8 +139,8 @@ public async Task SimpleProjectionForEntityJoinAsync()
119139 {
120140 EntityComplex ejComplex = null ;
121141 EntityWithNoAssociation root = null ;
122- var name = await ( session . QueryOver < EntityWithNoAssociation > ( ( ) => root )
123- . JoinEntityQueryOver ( ( ) => ejComplex , Restrictions . Where ( ( ) => root . Complex1Id == ejComplex . Id ) , JoinType . InnerJoin )
142+ var name = await ( session . QueryOver ( ( ) => root )
143+ . JoinEntityQueryOver ( ( ) => ejComplex , ( ) => root . Complex1Id == ejComplex . Id )
124144 . Select ( ( e ) => ejComplex . Name )
125145 . Take ( 1 )
126146 . SingleOrDefaultAsync < string > ( ) ) ;
@@ -141,9 +161,9 @@ public async Task EntityProjectionForEntityJoinAsync()
141161 EntityComplex root = null ;
142162 EntityComplex st = null ;
143163 var r = await ( session
144- . QueryOver < EntityComplex > ( ( ) => root )
164+ . QueryOver ( ( ) => root )
145165 . JoinAlias ( c => c . SameTypeChild , ( ) => st )
146- . JoinEntityAlias ( ( ) => ejChild1 , Restrictions . Where ( ( ) => ejChild1 . Id == root . Child1 . Id ) , JoinType . InnerJoin )
166+ . JoinEntityAlias ( ( ) => ejChild1 , ( ) => ejChild1 . Id == root . Child1 . Id )
147167 . Select (
148168 Projections . RootEntity ( ) ,
149169 Projections . Entity ( ( ) => st ) ,
@@ -177,11 +197,11 @@ public async Task MixOfJoinsForAssociatedAndNotAssociatedEntitiesAsync()
177197 EntityComplex entityComplexForEjLevel1 = null ;
178198 EntitySimpleChild ejLevel2OnEntityComplexForEjLevel1 = null ;
179199 var obj = await ( session
180- . QueryOver < EntityComplex > ( ( ) => root )
200+ . QueryOver ( ( ) => root )
181201 . JoinEntityAlias ( ( ) => ejLevel1 , Restrictions . Where ( ( ) => ejLevel1 . Id == root . SameTypeChild . Id && root . Id != null ) , JoinType . LeftOuterJoin )
182202 . JoinAlias ( ( ) => ejLevel1 . Child1 , ( ) => customChildForEjLevel1 , JoinType . InnerJoin )
183203 . JoinAlias ( ( ) => ejLevel1 . SameTypeChild , ( ) => entityComplexForEjLevel1 , JoinType . LeftOuterJoin )
184- . JoinEntityAlias ( ( ) => ejLevel2OnEntityComplexForEjLevel1 , Restrictions . Where ( ( ) => entityComplexForEjLevel1 . Id == ejLevel2OnEntityComplexForEjLevel1 . Id ) , JoinType . InnerJoin )
204+ . JoinEntityAlias ( ( ) => ejLevel2OnEntityComplexForEjLevel1 , ( ) => entityComplexForEjLevel1 . Id == ejLevel2OnEntityComplexForEjLevel1 . Id )
185205 . Where ( ( ) => customChildForEjLevel1 . Id != null && ejLevel2OnEntityComplexForEjLevel1 . Id != null )
186206 . Take ( 1 )
187207 . SingleOrDefaultAsync < object > ( ) ) ;
@@ -197,8 +217,8 @@ public async Task EntityJoinForCompositeKeyAsync()
197217 EntityWithCompositeId ejComposite = null ;
198218 EntityWithNoAssociation root = null ;
199219 root = await ( session
200- . QueryOver < EntityWithNoAssociation > ( ( ) => root )
201- . JoinEntityAlias ( ( ) => ejComposite , Restrictions . Where ( ( ) => root . Composite1Key1 == ejComposite . Key . Id1 && root . Composite1Key2 == ejComposite . Key . Id2 ) , JoinType . InnerJoin )
220+ . QueryOver ( ( ) => root )
221+ . JoinEntityAlias ( ( ) => ejComposite , ( ) => root . Composite1Key1 == ejComposite . Key . Id1 && root . Composite1Key2 == ejComposite . Key . Id2 )
202222 . Take ( 1 ) . SingleOrDefaultAsync ( ) ) ;
203223 var composite = await ( session . LoadAsync < EntityWithCompositeId > ( _entityWithCompositeId . Key ) ) ;
204224
@@ -216,9 +236,9 @@ public async Task NullLeftEntityJoinAsync()
216236 {
217237 EntityComplex ejLeftNull = null ;
218238 EntityWithNoAssociation root = null ;
219- root = await ( session . QueryOver < EntityWithNoAssociation > ( ( ) => root )
220- //add some non existent
221- . JoinEntityAlias ( ( ) => ejLeftNull , Restrictions . Where ( ( ) => ejLeftNull . Id == null ) , JoinType . LeftOuterJoin )
239+ root = await ( session . QueryOver ( ( ) => root )
240+ //add some non existent join condition
241+ . JoinEntityAlias ( ( ) => ejLeftNull , ( ) => ejLeftNull . Id == null , JoinType . LeftOuterJoin )
222242 . Take ( 1 )
223243 . SingleOrDefaultAsync ( ) ) ;
224244
@@ -236,9 +256,9 @@ public async Task NullLeftEntityJoinWithEntityProjectionAsync()
236256 {
237257 EntityComplex ejLeftNull = null ;
238258 EntityWithNoAssociation root = null ;
239- var objs = await ( session . QueryOver < EntityWithNoAssociation > ( ( ) => root )
240- //add some non existent
241- . JoinEntityAlias ( ( ) => ejLeftNull , Restrictions . Where ( ( ) => ejLeftNull . Id == null ) , JoinType . LeftOuterJoin )
259+ var objs = await ( session . QueryOver ( ( ) => root )
260+ //add some non existent join condition
261+ . JoinEntityAlias ( ( ) => ejLeftNull , ( ) => ejLeftNull . Id == null , JoinType . LeftOuterJoin )
242262 . Select ( ( e ) => root . AsEntity ( ) , e => ejLeftNull . AsEntity ( ) )
243263 . Take ( 1 )
244264 . SingleOrDefaultAsync < object [ ] > ( ) ) ;
@@ -261,12 +281,33 @@ public async Task EntityJoinForCustomEntityNameAsync()
261281 {
262282 EntityCustomEntityName ejCustomEntity = null ;
263283 EntityWithNoAssociation root = null ;
264- root = await ( session . QueryOver < EntityWithNoAssociation > ( ( ) => root )
284+ root = await ( session . QueryOver ( ( ) => root )
265285 . JoinEntityAlias ( ( ) => ejCustomEntity , Restrictions . Where ( ( ) => ejCustomEntity . Id == root . CustomEntityNameId ) , JoinType . InnerJoin , customEntityName )
266286 . Take ( 1 )
267287 . SingleOrDefaultAsync ( ) ) ;
268288
269- ejCustomEntity = await ( session . LoadAsync < EntityCustomEntityName > ( root . CustomEntityNameId ) ) ;
289+ ejCustomEntity = ( EntityCustomEntityName ) await ( session . LoadAsync ( customEntityName , root . CustomEntityNameId ) ) ;
290+
291+ Assert . That ( NHibernateUtil . IsInitialized ( ejCustomEntity ) , Is . True ) ;
292+ Assert . That ( sqlLog . Appender . GetEvents ( ) . Length , Is . EqualTo ( 1 ) , "Only one SQL select is expected" ) ;
293+ }
294+ }
295+
296+ [ Test ]
297+ public async Task EntityJoinForCustomEntityName_ExpressionAsync ( )
298+ {
299+
300+ using ( var sqlLog = new SqlLogSpy ( ) )
301+ using ( var session = OpenSession ( ) )
302+ {
303+ EntityCustomEntityName ejCustomEntity = null ;
304+ EntityWithNoAssociation root = null ;
305+ root = await ( session . QueryOver ( ( ) => root )
306+ . JoinEntityAlias ( ( ) => ejCustomEntity , ( ) => ejCustomEntity . Id == root . CustomEntityNameId , JoinType . InnerJoin , customEntityName )
307+ . Take ( 1 )
308+ . SingleOrDefaultAsync ( ) ) ;
309+
310+ ejCustomEntity = ( EntityCustomEntityName ) await ( session . LoadAsync ( customEntityName , root . CustomEntityNameId ) ) ;
270311
271312 Assert . That ( NHibernateUtil . IsInitialized ( ejCustomEntity ) , Is . True ) ;
272313 Assert . That ( sqlLog . Appender . GetEvents ( ) . Length , Is . EqualTo ( 1 ) , "Only one SQL select is expected" ) ;
@@ -285,13 +326,13 @@ public async Task EntityJoinFoSubquery_JoinEntityAliasAsync()
285326 EntityComplex ejSub = null ;
286327 EntityWithNoAssociation rootSub = null ;
287328
288- var subquery = QueryOver . Of < EntityWithNoAssociation > ( ( ) => rootSub )
329+ var subquery = QueryOver . Of ( ( ) => rootSub )
289330 . JoinEntityAlias ( ( ) => ejSub , ( ) => rootSub . Complex1Id == ejSub . Id )
290331 . Where ( r => ejSub . Name == ej . Name )
291332 . Select ( x => ejSub . Id ) ;
292333
293334 root = await ( session . QueryOver ( ( ) => root )
294- . JoinEntityAlias ( ( ) => ej , Restrictions . Where ( ( ) => root . Complex1Id == ej . Id ) )
335+ . JoinEntityAlias ( ( ) => ej , ( ) => root . Complex1Id == ej . Id )
295336 . WithSubquery . WhereExists ( subquery )
296337 . SingleOrDefaultAsync ( ) ) ;
297338 ej = await ( session . LoadAsync < EntityComplex > ( root . Complex1Id ) ) ;
@@ -313,13 +354,13 @@ public async Task EntityJoinFoSubquery_JoinQueryOverAsync()
313354 EntityComplex ejSub = null ;
314355 EntityWithNoAssociation rootSub = null ;
315356
316- var subquery = QueryOver . Of < EntityWithNoAssociation > ( ( ) => rootSub )
357+ var subquery = QueryOver . Of ( ( ) => rootSub )
317358 . JoinEntityQueryOver ( ( ) => ejSub , ( ) => rootSub . Complex1Id == ejSub . Id )
318359 . Where ( x => x . Name == ej . Name )
319360 . Select ( x => ejSub . Id ) ;
320361
321362 root = await ( session . QueryOver ( ( ) => root )
322- . JoinEntityAlias ( ( ) => ej , Restrictions . Where ( ( ) => root . Complex1Id == ej . Id ) )
363+ . JoinEntityAlias ( ( ) => ej , ( ) => root . Complex1Id == ej . Id )
323364 . WithSubquery . WhereExists ( subquery )
324365 . SingleOrDefaultAsync ( ) ) ;
325366 ej = await ( session . LoadAsync < EntityComplex > ( root . Complex1Id ) ) ;
0 commit comments