@@ -174,6 +174,53 @@ public async Task SelectModeFetchLazyPropertiesAsync()
174
174
Assert . That ( NHibernateUtil . IsInitialized ( root ) , Is . True ) ;
175
175
Assert . That ( root . LazyProp , Is . Not . Null ) ;
176
176
Assert . That ( NHibernateUtil . IsPropertyInitialized ( root , nameof ( root . LazyProp ) ) , Is . True , "Lazy property must be fetched." ) ;
177
+ Assert . That ( NHibernateUtil . IsPropertyInitialized ( root , nameof ( root . LazyProp2 ) ) , Is . True , "Lazy property must be fetched." ) ;
178
+
179
+ Assert . That ( sqlLog . Appender . GetEvents ( ) . Length , Is . EqualTo ( 1 ) , "Only one SQL select is expected" ) ;
180
+ }
181
+ }
182
+
183
+ [ Test ]
184
+ public async Task SelectModeFetchKeepLazyPropertiesUninitializedAsync ( )
185
+ {
186
+ using ( var sqlLog = new SqlLogSpy ( ) )
187
+ using ( var session = OpenSession ( ) )
188
+ {
189
+ var root = await ( session . QueryOver < EntityComplex > ( )
190
+ . Fetch ( SelectMode . Fetch , ec => ec )
191
+ . Where ( ec => ec . LazyProp != null )
192
+ . Take ( 1 )
193
+ . SingleOrDefaultAsync ( ) ) ;
194
+
195
+ Assert . That ( root , Is . Not . Null ) ;
196
+ Assert . That ( NHibernateUtil . IsInitialized ( root ) , Is . True ) ;
197
+ Assert . That ( NHibernateUtil . IsPropertyInitialized ( root , nameof ( root . LazyProp ) ) , Is . False , "Property must be lazy." ) ;
198
+ Assert . That ( NHibernateUtil . IsPropertyInitialized ( root , nameof ( root . LazyProp2 ) ) , Is . False , "Property must be lazy." ) ;
199
+
200
+ Assert . That ( sqlLog . Appender . GetEvents ( ) . Length , Is . EqualTo ( 1 ) , "Only one SQL select is expected" ) ;
201
+ }
202
+ }
203
+
204
+ [ Test ]
205
+ public async Task SelectModeFetchLazyPropertiesFetchGroupAsync ( )
206
+ {
207
+ using ( var sqlLog = new SqlLogSpy ( ) )
208
+ using ( var session = OpenSession ( ) )
209
+ {
210
+ var root = await ( session . QueryOver < EntityComplex > ( )
211
+ . Fetch ( SelectMode . FetchLazyPropertyGroup , ec => ec . LazyProp , ec => ec . LazyProp2 , ec => ec . SameTypeChild . LazyProp2 )
212
+ . Where ( ec => ec . Id == _parentEntityComplexId )
213
+ . SingleOrDefaultAsync ( ) ) ;
214
+
215
+ Assert . That ( root , Is . Not . Null ) ;
216
+ Assert . That ( NHibernateUtil . IsInitialized ( root ) , Is . True ) ;
217
+ Assert . That ( root . LazyProp , Is . Not . Null ) ;
218
+ Assert . That ( NHibernateUtil . IsPropertyInitialized ( root , nameof ( root . LazyProp ) ) , Is . True , "Lazy property must be fetched." ) ;
219
+ Assert . That ( NHibernateUtil . IsPropertyInitialized ( root , nameof ( root . LazyProp2 ) ) , Is . True , "Lazy property must be fetched." ) ;
220
+ Assert . That ( NHibernateUtil . IsInitialized ( root . SameTypeChild ) , Is . True , "Object must be initialized." ) ;
221
+ Assert . That ( root . SameTypeChild , Is . Not . Null ) ;
222
+ Assert . That ( NHibernateUtil . IsPropertyInitialized ( root . SameTypeChild , nameof ( root . LazyProp2 ) ) , Is . True , "Lazy property must be fetched." ) ;
223
+ Assert . That ( NHibernateUtil . IsPropertyInitialized ( root . SameTypeChild , nameof ( root . LazyProp ) ) , Is . False , "Property must be lazy." ) ;
177
224
178
225
Assert . That ( sqlLog . Appender . GetEvents ( ) . Length , Is . EqualTo ( 1 ) , "Only one SQL select is expected" ) ;
179
226
}
@@ -579,7 +626,16 @@ protected override HbmMapping GetMappings()
579
626
580
627
rc . Property ( x => x . Name ) ;
581
628
582
- rc . Property ( ep => ep . LazyProp , m => m . Lazy ( true ) ) ;
629
+ rc . Property ( ep => ep . LazyProp , m =>
630
+ {
631
+ m . Lazy ( true ) ;
632
+ m . FetchGroup ( "LazyGroup" ) ;
633
+ } ) ;
634
+ rc . Property ( ep => ep . LazyProp2 , m =>
635
+ {
636
+ m . Lazy ( true ) ;
637
+ m . FetchGroup ( "LazyGroup2" ) ;
638
+ } ) ;
583
639
584
640
rc . ManyToOne (
585
641
ep => ep . Child1 ,
@@ -751,9 +807,12 @@ protected override void OnSetUp()
751
807
Child1 = child1 ,
752
808
Child2 = child2 ,
753
809
LazyProp = "SomeBigValue" ,
810
+ LazyProp2 = "SomeBigValue2" ,
754
811
SameTypeChild = new EntityComplex ( )
755
812
{
756
- Name = "ComplexEntityChild"
813
+ Name = "ComplexEntityChild" ,
814
+ LazyProp = "LazyProp1" ,
815
+ LazyProp2 = "LazyProp2" ,
757
816
} ,
758
817
ChildrenList = new List < EntitySimpleChild > { child3 , child1 , child4 } ,
759
818
ChildrenListEmpty = new List < EntityComplex > { } ,
0 commit comments