File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
src/NHibernate.Test/Stateless/FetchingLazyCollections Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Linq ;
3
4
using NHibernate . Cfg . MappingSchema ;
4
5
using NHibernate . Mapping . ByCode ;
5
6
using NHibernate . Mapping . ByCode . Conformist ;
7
+ using NHibernate . Linq ;
6
8
using NUnit . Framework ;
7
9
using SharpTestsEx ;
8
10
@@ -129,6 +131,24 @@ public void ShouldWorkLoadingComplexEntities()
129
131
tx . Commit ( ) ;
130
132
}
131
133
134
+ using ( IStatelessSession s = sessions . OpenStatelessSession ( ) )
135
+ using ( ITransaction tx = s . BeginTransaction ( ) )
136
+ {
137
+ IList < Family < Human > > hf = s . Query < Family < Human > > ( ) . FetchMany ( f => f . Childs ) . ToList ( ) ;
138
+ Assert . That ( hf . Count , Is . EqualTo ( 1 ) ) ;
139
+ Assert . That ( hf [ 0 ] . Father . Name , Is . EqualTo ( humanFather ) ) ;
140
+ Assert . That ( hf [ 0 ] . Mother . Name , Is . EqualTo ( humanMother ) ) ;
141
+ NHibernateUtil . IsInitialized ( hf [ 0 ] . Childs ) . Should ( "Lazy collection should be initialized" ) . Be . True ( ) ;
142
+
143
+ IList < Family < Reptile > > rf = s . Query < Family < Reptile > > ( ) . FetchMany ( f => f . Childs ) . ToList ( ) ;
144
+ Assert . That ( rf . Count , Is . EqualTo ( 1 ) ) ;
145
+ Assert . That ( rf [ 0 ] . Father . Description , Is . EqualTo ( crocodileFather ) ) ;
146
+ Assert . That ( rf [ 0 ] . Mother . Description , Is . EqualTo ( crocodileMother ) ) ;
147
+ NHibernateUtil . IsInitialized ( hf [ 0 ] . Childs ) . Should ( "Lazy collection should be initialized" ) . Be . True ( ) ;
148
+
149
+ tx . Commit ( ) ;
150
+ }
151
+
132
152
using ( ISession s = sessions . OpenSession ( ) )
133
153
using ( ITransaction tx = s . BeginTransaction ( ) )
134
154
{
You can’t perform that action at this time.
0 commit comments