@@ -38,8 +38,8 @@ public async Task CanJoinNotAssociatedEntityAsync()
38
38
{
39
39
EntityComplex entityComplex = null ;
40
40
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 )
43
43
. SingleOrDefaultAsync ( ) ) ;
44
44
entityComplex = await ( session . LoadAsync < EntityComplex > ( root . Complex1Id ) ) ;
45
45
@@ -76,8 +76,28 @@ public async Task CanJoinEntityQueryOverAsync()
76
76
{
77
77
EntityComplex ejQueryOver = null ;
78
78
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 )
81
101
. Take ( 1 )
82
102
. SingleOrDefaultAsync ( ) ) ;
83
103
ejQueryOver = await ( session . LoadAsync < EntityComplex > ( root . Complex1Id ) ) ;
@@ -96,8 +116,8 @@ public async Task CanQueryOverForAssociationInNotAssociatedEntityAsync()
96
116
{
97
117
EntityComplex ejComplex = null ;
98
118
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 )
101
121
. JoinQueryOver ( ej => ej . Child1 )
102
122
. Take ( 1 )
103
123
. SingleOrDefaultAsync ( ) ) ;
@@ -119,8 +139,8 @@ public async Task SimpleProjectionForEntityJoinAsync()
119
139
{
120
140
EntityComplex ejComplex = null ;
121
141
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 )
124
144
. Select ( ( e ) => ejComplex . Name )
125
145
. Take ( 1 )
126
146
. SingleOrDefaultAsync < string > ( ) ) ;
@@ -141,9 +161,9 @@ public async Task EntityProjectionForEntityJoinAsync()
141
161
EntityComplex root = null ;
142
162
EntityComplex st = null ;
143
163
var r = await ( session
144
- . QueryOver < EntityComplex > ( ( ) => root )
164
+ . QueryOver ( ( ) => root )
145
165
. 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 )
147
167
. Select (
148
168
Projections . RootEntity ( ) ,
149
169
Projections . Entity ( ( ) => st ) ,
@@ -177,11 +197,11 @@ public async Task MixOfJoinsForAssociatedAndNotAssociatedEntitiesAsync()
177
197
EntityComplex entityComplexForEjLevel1 = null ;
178
198
EntitySimpleChild ejLevel2OnEntityComplexForEjLevel1 = null ;
179
199
var obj = await ( session
180
- . QueryOver < EntityComplex > ( ( ) => root )
200
+ . QueryOver ( ( ) => root )
181
201
. JoinEntityAlias ( ( ) => ejLevel1 , Restrictions . Where ( ( ) => ejLevel1 . Id == root . SameTypeChild . Id && root . Id != null ) , JoinType . LeftOuterJoin )
182
202
. JoinAlias ( ( ) => ejLevel1 . Child1 , ( ) => customChildForEjLevel1 , JoinType . InnerJoin )
183
203
. JoinAlias ( ( ) => ejLevel1 . SameTypeChild , ( ) => entityComplexForEjLevel1 , JoinType . LeftOuterJoin )
184
- . JoinEntityAlias ( ( ) => ejLevel2OnEntityComplexForEjLevel1 , Restrictions . Where ( ( ) => entityComplexForEjLevel1 . Id == ejLevel2OnEntityComplexForEjLevel1 . Id ) , JoinType . InnerJoin )
204
+ . JoinEntityAlias ( ( ) => ejLevel2OnEntityComplexForEjLevel1 , ( ) => entityComplexForEjLevel1 . Id == ejLevel2OnEntityComplexForEjLevel1 . Id )
185
205
. Where ( ( ) => customChildForEjLevel1 . Id != null && ejLevel2OnEntityComplexForEjLevel1 . Id != null )
186
206
. Take ( 1 )
187
207
. SingleOrDefaultAsync < object > ( ) ) ;
@@ -197,8 +217,8 @@ public async Task EntityJoinForCompositeKeyAsync()
197
217
EntityWithCompositeId ejComposite = null ;
198
218
EntityWithNoAssociation root = null ;
199
219
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 )
202
222
. Take ( 1 ) . SingleOrDefaultAsync ( ) ) ;
203
223
var composite = await ( session . LoadAsync < EntityWithCompositeId > ( _entityWithCompositeId . Key ) ) ;
204
224
@@ -216,9 +236,9 @@ public async Task NullLeftEntityJoinAsync()
216
236
{
217
237
EntityComplex ejLeftNull = null ;
218
238
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 )
222
242
. Take ( 1 )
223
243
. SingleOrDefaultAsync ( ) ) ;
224
244
@@ -236,9 +256,9 @@ public async Task NullLeftEntityJoinWithEntityProjectionAsync()
236
256
{
237
257
EntityComplex ejLeftNull = null ;
238
258
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 )
242
262
. Select ( ( e ) => root . AsEntity ( ) , e => ejLeftNull . AsEntity ( ) )
243
263
. Take ( 1 )
244
264
. SingleOrDefaultAsync < object [ ] > ( ) ) ;
@@ -261,12 +281,33 @@ public async Task EntityJoinForCustomEntityNameAsync()
261
281
{
262
282
EntityCustomEntityName ejCustomEntity = null ;
263
283
EntityWithNoAssociation root = null ;
264
- root = await ( session . QueryOver < EntityWithNoAssociation > ( ( ) => root )
284
+ root = await ( session . QueryOver ( ( ) => root )
265
285
. JoinEntityAlias ( ( ) => ejCustomEntity , Restrictions . Where ( ( ) => ejCustomEntity . Id == root . CustomEntityNameId ) , JoinType . InnerJoin , customEntityName )
266
286
. Take ( 1 )
267
287
. SingleOrDefaultAsync ( ) ) ;
268
288
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 ) ) ;
270
311
271
312
Assert . That ( NHibernateUtil . IsInitialized ( ejCustomEntity ) , Is . True ) ;
272
313
Assert . That ( sqlLog . Appender . GetEvents ( ) . Length , Is . EqualTo ( 1 ) , "Only one SQL select is expected" ) ;
@@ -285,13 +326,13 @@ public async Task EntityJoinFoSubquery_JoinEntityAliasAsync()
285
326
EntityComplex ejSub = null ;
286
327
EntityWithNoAssociation rootSub = null ;
287
328
288
- var subquery = QueryOver . Of < EntityWithNoAssociation > ( ( ) => rootSub )
329
+ var subquery = QueryOver . Of ( ( ) => rootSub )
289
330
. JoinEntityAlias ( ( ) => ejSub , ( ) => rootSub . Complex1Id == ejSub . Id )
290
331
. Where ( r => ejSub . Name == ej . Name )
291
332
. Select ( x => ejSub . Id ) ;
292
333
293
334
root = await ( session . QueryOver ( ( ) => root )
294
- . JoinEntityAlias ( ( ) => ej , Restrictions . Where ( ( ) => root . Complex1Id == ej . Id ) )
335
+ . JoinEntityAlias ( ( ) => ej , ( ) => root . Complex1Id == ej . Id )
295
336
. WithSubquery . WhereExists ( subquery )
296
337
. SingleOrDefaultAsync ( ) ) ;
297
338
ej = await ( session . LoadAsync < EntityComplex > ( root . Complex1Id ) ) ;
@@ -313,13 +354,13 @@ public async Task EntityJoinFoSubquery_JoinQueryOverAsync()
313
354
EntityComplex ejSub = null ;
314
355
EntityWithNoAssociation rootSub = null ;
315
356
316
- var subquery = QueryOver . Of < EntityWithNoAssociation > ( ( ) => rootSub )
357
+ var subquery = QueryOver . Of ( ( ) => rootSub )
317
358
. JoinEntityQueryOver ( ( ) => ejSub , ( ) => rootSub . Complex1Id == ejSub . Id )
318
359
. Where ( x => x . Name == ej . Name )
319
360
. Select ( x => ejSub . Id ) ;
320
361
321
362
root = await ( session . QueryOver ( ( ) => root )
322
- . JoinEntityAlias ( ( ) => ej , Restrictions . Where ( ( ) => root . Complex1Id == ej . Id ) )
363
+ . JoinEntityAlias ( ( ) => ej , ( ) => root . Complex1Id == ej . Id )
323
364
. WithSubquery . WhereExists ( subquery )
324
365
. SingleOrDefaultAsync ( ) ) ;
325
366
ej = await ( session . LoadAsync < EntityComplex > ( root . Complex1Id ) ) ;
0 commit comments