Skip to content

Commit 9262202

Browse files
unknownoskarb
authored andcommitted
Linq Unit Test for Join Fetch with Stateless Session
Shows that the change made in StatelessSessionImpl.GetEntityUsingInterceptor effectively eliminates Duplicates in a Linq query with Join Fetch.
1 parent c436a8c commit 9262202

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/NHibernate.Test/Stateless/FetchingLazyCollections/LazyCollectionFetchTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using NHibernate.Cfg.MappingSchema;
45
using NHibernate.Mapping.ByCode;
56
using NHibernate.Mapping.ByCode.Conformist;
7+
using NHibernate.Linq;
68
using NUnit.Framework;
79
using SharpTestsEx;
810

@@ -129,6 +131,24 @@ public void ShouldWorkLoadingComplexEntities()
129131
tx.Commit();
130132
}
131133

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+
132152
using (ISession s = sessions.OpenSession())
133153
using (ITransaction tx = s.BeginTransaction())
134154
{

0 commit comments

Comments
 (0)