@@ -28,7 +28,26 @@ public void CanJoinNotAssociatedEntity()
28
28
EntityComplex entityComplex = null ;
29
29
EntityWithNoAssociation root = null ;
30
30
root = session . QueryOver < EntityWithNoAssociation > ( ( ) => root )
31
- . JoinEntityAlias ( ( ) => entityComplex , JoinType . InnerJoin , Restrictions . Where ( ( ) => root . Complex1Id == entityComplex . Id ) ) . Take ( 1 )
31
+ . JoinEntityAlias ( ( ) => entityComplex , Restrictions . Where ( ( ) => root . Complex1Id == entityComplex . Id ) , JoinType . InnerJoin ) . Take ( 1 )
32
+ . SingleOrDefault ( ) ;
33
+ entityComplex = session . Load < EntityComplex > ( root . Complex1Id ) ;
34
+
35
+ Assert . That ( NHibernateUtil . IsInitialized ( entityComplex ) , Is . True ) ;
36
+ Assert . That ( sqlLog . Appender . GetEvents ( ) . Length , Is . EqualTo ( 1 ) , "Only one SQL select is expected" ) ;
37
+ }
38
+ }
39
+
40
+ //check JoinEntityAlias - JoinAlias analog for entity join
41
+ [ Test ]
42
+ public void CanJoinNotAssociatedEntity_Expression ( )
43
+ {
44
+ using ( var sqlLog = new SqlLogSpy ( ) )
45
+ using ( var session = OpenSession ( ) )
46
+ {
47
+ EntityComplex entityComplex = null ;
48
+ EntityWithNoAssociation root = null ;
49
+ root = session . QueryOver ( ( ) => root )
50
+ . JoinEntityAlias ( ( ) => entityComplex , ( ) => root . Complex1Id == entityComplex . Id ) . Take ( 1 )
32
51
. SingleOrDefault ( ) ;
33
52
entityComplex = session . Load < EntityComplex > ( root . Complex1Id ) ;
34
53
@@ -47,7 +66,7 @@ public void CanJoinEntityQueryOver()
47
66
EntityComplex ejQueryOver = null ;
48
67
EntityWithNoAssociation root = null ;
49
68
root = session . QueryOver < EntityWithNoAssociation > ( ( ) => root )
50
- . JoinEntityQueryOver ( ( ) => ejQueryOver , JoinType . InnerJoin , Restrictions . Where ( ( ) => root . Complex1Id == ejQueryOver . Id ) )
69
+ . JoinEntityQueryOver ( ( ) => ejQueryOver , Restrictions . Where ( ( ) => root . Complex1Id == ejQueryOver . Id ) , JoinType . InnerJoin )
51
70
. Take ( 1 )
52
71
. SingleOrDefault ( ) ;
53
72
ejQueryOver = session . Load < EntityComplex > ( root . Complex1Id ) ;
@@ -67,7 +86,7 @@ public void CanQueryOverForAssociationInNotAssociatedEntity()
67
86
EntityComplex ejComplex = null ;
68
87
EntityWithNoAssociation root = null ;
69
88
root = session . QueryOver < EntityWithNoAssociation > ( ( ) => root )
70
- . JoinEntityQueryOver ( ( ) => ejComplex , JoinType . InnerJoin , Restrictions . Where ( ( ) => root . Complex1Id == ejComplex . Id ) )
89
+ . JoinEntityQueryOver ( ( ) => ejComplex , Restrictions . Where ( ( ) => root . Complex1Id == ejComplex . Id ) , JoinType . InnerJoin )
71
90
. JoinQueryOver ( ej => ej . Child1 )
72
91
. Take ( 1 )
73
92
. SingleOrDefault ( ) ;
@@ -90,7 +109,7 @@ public void SimpleProjectionForEntityJoin()
90
109
EntityComplex ejComplex = null ;
91
110
EntityWithNoAssociation root = null ;
92
111
var name = session . QueryOver < EntityWithNoAssociation > ( ( ) => root )
93
- . JoinEntityQueryOver ( ( ) => ejComplex , JoinType . InnerJoin , Restrictions . Where ( ( ) => root . Complex1Id == ejComplex . Id ) )
112
+ . JoinEntityQueryOver ( ( ) => ejComplex , Restrictions . Where ( ( ) => root . Complex1Id == ejComplex . Id ) , JoinType . InnerJoin )
94
113
. Select ( ( e ) => ejComplex . Name )
95
114
. Take ( 1 )
96
115
. SingleOrDefault < string > ( ) ;
@@ -113,7 +132,7 @@ public void EntityProjectionForEntityJoin()
113
132
var r = session
114
133
. QueryOver < EntityComplex > ( ( ) => root )
115
134
. JoinAlias ( c => c . SameTypeChild , ( ) => st )
116
- . JoinEntityAlias ( ( ) => ejChild1 , JoinType . InnerJoin , Restrictions . Where ( ( ) => ejChild1 . Id == root . Child1 . Id ) )
135
+ . JoinEntityAlias ( ( ) => ejChild1 , Restrictions . Where ( ( ) => ejChild1 . Id == root . Child1 . Id ) , JoinType . InnerJoin )
117
136
. Select (
118
137
Projections . RootEntity ( ) ,
119
138
Projections . Entity ( ( ) => st ) ,
@@ -148,10 +167,10 @@ public void MixOfJoinsForAssociatedAndNotAssociatedEntities()
148
167
EntitySimpleChild ejLevel2OnEntityComplexForEjLevel1 = null ;
149
168
var obj = session
150
169
. QueryOver < EntityComplex > ( ( ) => root )
151
- . JoinEntityAlias ( ( ) => ejLevel1 , JoinType . LeftOuterJoin , Restrictions . Where ( ( ) => ejLevel1 . Id == root . SameTypeChild . Id && root . Id != null ) )
170
+ . JoinEntityAlias ( ( ) => ejLevel1 , Restrictions . Where ( ( ) => ejLevel1 . Id == root . SameTypeChild . Id && root . Id != null ) , JoinType . LeftOuterJoin )
152
171
. JoinAlias ( ( ) => ejLevel1 . Child1 , ( ) => customChildForEjLevel1 , JoinType . InnerJoin )
153
172
. JoinAlias ( ( ) => ejLevel1 . SameTypeChild , ( ) => entityComplexForEjLevel1 , JoinType . LeftOuterJoin )
154
- . JoinEntityAlias ( ( ) => ejLevel2OnEntityComplexForEjLevel1 , JoinType . InnerJoin , Restrictions . Where ( ( ) => entityComplexForEjLevel1 . Id == ejLevel2OnEntityComplexForEjLevel1 . Id ) )
173
+ . JoinEntityAlias ( ( ) => ejLevel2OnEntityComplexForEjLevel1 , Restrictions . Where ( ( ) => entityComplexForEjLevel1 . Id == ejLevel2OnEntityComplexForEjLevel1 . Id ) , JoinType . InnerJoin )
155
174
. Where ( ( ) => customChildForEjLevel1 . Id != null && ejLevel2OnEntityComplexForEjLevel1 . Id != null )
156
175
. Take ( 1 )
157
176
. SingleOrDefault < object > ( ) ;
@@ -168,7 +187,7 @@ public void EntityJoinForCompositeKey()
168
187
EntityWithNoAssociation root = null ;
169
188
root = session
170
189
. QueryOver < EntityWithNoAssociation > ( ( ) => root )
171
- . JoinEntityAlias ( ( ) => ejComposite , JoinType . InnerJoin , Restrictions . Where ( ( ) => root . Composite1Key1 == ejComposite . Key . Id1 && root . Composite1Key2 == ejComposite . Key . Id2 ) )
190
+ . JoinEntityAlias ( ( ) => ejComposite , Restrictions . Where ( ( ) => root . Composite1Key1 == ejComposite . Key . Id1 && root . Composite1Key2 == ejComposite . Key . Id2 ) , JoinType . InnerJoin )
172
191
. Take ( 1 ) . SingleOrDefault ( ) ;
173
192
var composite = session . Load < EntityWithCompositeId > ( _entityWithCompositeId . Key ) ;
174
193
@@ -188,7 +207,7 @@ public void NullLeftEntityJoin()
188
207
EntityWithNoAssociation root = null ;
189
208
root = session . QueryOver < EntityWithNoAssociation > ( ( ) => root )
190
209
//add some non existent
191
- . JoinEntityAlias ( ( ) => ejLeftNull , JoinType . LeftOuterJoin , Restrictions . Where ( ( ) => ejLeftNull . Id == null ) )
210
+ . JoinEntityAlias ( ( ) => ejLeftNull , Restrictions . Where ( ( ) => ejLeftNull . Id == null ) , JoinType . LeftOuterJoin )
192
211
. Take ( 1 )
193
212
. SingleOrDefault ( ) ;
194
213
@@ -208,7 +227,7 @@ public void NullLeftEntityJoinWithEntityProjection()
208
227
EntityWithNoAssociation root = null ;
209
228
var objs = session . QueryOver < EntityWithNoAssociation > ( ( ) => root )
210
229
//add some non existent
211
- . JoinEntityAlias ( ( ) => ejLeftNull , JoinType . LeftOuterJoin , Restrictions . Where ( ( ) => ejLeftNull . Id == null ) )
230
+ . JoinEntityAlias ( ( ) => ejLeftNull , Restrictions . Where ( ( ) => ejLeftNull . Id == null ) , JoinType . LeftOuterJoin )
212
231
. Select ( ( e ) => root . AsEntity ( ) , e => ejLeftNull . AsEntity ( ) )
213
232
. Take ( 1 )
214
233
. SingleOrDefault < object [ ] > ( ) ;
@@ -232,7 +251,7 @@ public void EntityJoinForCustomEntityName()
232
251
EntityCustomEntityName ejCustomEntity = null ;
233
252
EntityWithNoAssociation root = null ;
234
253
root = session . QueryOver < EntityWithNoAssociation > ( ( ) => root )
235
- . JoinEntityAlias ( ( ) => ejCustomEntity , JoinType . InnerJoin , Restrictions . Where ( ( ) => ejCustomEntity . Id == root . CustomEntityNameId ) , customEntityName )
254
+ . JoinEntityAlias ( ( ) => ejCustomEntity , Restrictions . Where ( ( ) => ejCustomEntity . Id == root . CustomEntityNameId ) , JoinType . InnerJoin , customEntityName )
236
255
. Take ( 1 )
237
256
. SingleOrDefault ( ) ;
238
257
@@ -243,6 +262,61 @@ public void EntityJoinForCustomEntityName()
243
262
}
244
263
}
245
264
265
+ [ Test ]
266
+ public void EntityJoinFoSubquery_JoinEntityAlias ( )
267
+ {
268
+ using ( var sqlLog = new SqlLogSpy ( ) )
269
+ using ( var session = OpenSession ( ) )
270
+ {
271
+ EntityComplex ej = null ;
272
+ EntityWithNoAssociation root = null ;
273
+
274
+ EntityComplex ejSub = null ;
275
+ EntityWithNoAssociation rootSub = null ;
276
+
277
+ var subquery = QueryOver . Of < EntityWithNoAssociation > ( ( ) => rootSub )
278
+ . JoinEntityAlias ( ( ) => ejSub , ( ) => rootSub . Complex1Id == ejSub . Id )
279
+ . Where ( r => ejSub . Name == ej . Name )
280
+ . Select ( x => ejSub . Id ) ;
281
+
282
+ root = session . QueryOver ( ( ) => root )
283
+ . JoinEntityAlias ( ( ) => ej , Restrictions . Where ( ( ) => root . Complex1Id == ej . Id ) )
284
+ . WithSubquery . WhereExists ( subquery )
285
+ . SingleOrDefault ( ) ;
286
+ ej = session . Load < EntityComplex > ( root . Complex1Id ) ;
287
+
288
+ Assert . That ( NHibernateUtil . IsInitialized ( ej ) , Is . True ) ;
289
+ Assert . That ( sqlLog . Appender . GetEvents ( ) . Length , Is . EqualTo ( 1 ) , "Only one SQL select is expected" ) ;
290
+ }
291
+ }
292
+
293
+ [ Test ]
294
+ public void EntityJoinFoSubquery_JoinQueryOver ( )
295
+ {
296
+ using ( var sqlLog = new SqlLogSpy ( ) )
297
+ using ( var session = OpenSession ( ) )
298
+ {
299
+ EntityComplex ej = null ;
300
+ EntityWithNoAssociation root = null ;
301
+
302
+ EntityComplex ejSub = null ;
303
+ EntityWithNoAssociation rootSub = null ;
304
+
305
+ var subquery = QueryOver . Of < EntityWithNoAssociation > ( ( ) => rootSub )
306
+ . JoinEntityQueryOver ( ( ) => ejSub , ( ) => rootSub . Complex1Id == ejSub . Id )
307
+ . Where ( x => x . Name == ej . Name )
308
+ . Select ( x => ejSub . Id ) ;
309
+
310
+ root = session . QueryOver ( ( ) => root )
311
+ . JoinEntityAlias ( ( ) => ej , Restrictions . Where ( ( ) => root . Complex1Id == ej . Id ) )
312
+ . WithSubquery . WhereExists ( subquery )
313
+ . SingleOrDefault ( ) ;
314
+ ej = session . Load < EntityComplex > ( root . Complex1Id ) ;
315
+
316
+ Assert . That ( NHibernateUtil . IsInitialized ( ej ) , Is . True ) ;
317
+ Assert . That ( sqlLog . Appender . GetEvents ( ) . Length , Is . EqualTo ( 1 ) , "Only one SQL select is expected" ) ;
318
+ }
319
+ }
246
320
#region Test Setup
247
321
248
322
protected override HbmMapping GetMappings ( )
0 commit comments