Skip to content

Commit cb9b233

Browse files
committed
NH-3909 - Fixed a regression bug caused by NH-3797 and NH-3801 changes
1 parent 3d0628f commit cb9b233

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH3909
4+
{
5+
public class ParentEntity
6+
{
7+
public virtual Guid Id { get; set; }
8+
public virtual string Name { get; set; }
9+
}
10+
11+
12+
public class ChildEntity
13+
{
14+
public virtual Guid Id { get; set; }
15+
public virtual string Name { get; set; }
16+
public virtual ParentEntity Parent { get; set; }
17+
}
18+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System.Linq;
2+
using NHibernate.Cfg.MappingSchema;
3+
using NHibernate.Linq;
4+
using NHibernate.Mapping.ByCode;
5+
using NUnit.Framework;
6+
7+
namespace NHibernate.Test.NHSpecificTest.NH3909
8+
{
9+
public class FixtureByCode : TestCaseMappingByCode
10+
{
11+
protected override HbmMapping GetMappings()
12+
{
13+
var mapper = new ModelMapper();
14+
mapper.Class<ParentEntity>(rc =>
15+
{
16+
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
17+
rc.Property(x => x.Name);
18+
});
19+
20+
mapper.Class<ChildEntity>(rc =>
21+
{
22+
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
23+
rc.Property(x => x.Name);
24+
rc.ManyToOne(x => x.Parent, m =>
25+
{
26+
m.Column("Parent");
27+
});
28+
});
29+
30+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
31+
}
32+
33+
protected override void OnSetUp()
34+
{
35+
using (var session = OpenSession())
36+
using (var transaction = session.BeginTransaction())
37+
{
38+
var e1 = new ParentEntity { Name = "Parent" };
39+
session.Save(e1);
40+
41+
var e2 = new ChildEntity { Name = "ChildWithParent", Parent = e1 };
42+
session.Save(e2);
43+
44+
var e3 = new ChildEntity { Name = "ChildWithoutParent", Parent = null };
45+
session.Save(e3);
46+
47+
session.Flush();
48+
transaction.Commit();
49+
}
50+
}
51+
52+
protected override void OnTearDown()
53+
{
54+
using (var session = OpenSession())
55+
using (var transaction = session.BeginTransaction())
56+
{
57+
session.Delete("from ParentEntity");
58+
session.Delete("from ChildEntity");
59+
60+
session.Flush();
61+
transaction.Commit();
62+
}
63+
}
64+
65+
[Test]
66+
public void YourTestName()
67+
{
68+
using (var session = OpenSession())
69+
using (session.BeginTransaction())
70+
{
71+
var q = from b in session.Query<ChildEntity>()
72+
select new
73+
{
74+
Id = b.Id,
75+
Name = b.Name,
76+
Parent = b.Parent
77+
};
78+
//select b;
79+
80+
Assert.AreEqual(2, q.ToList().Count);
81+
82+
}
83+
}
84+
}
85+
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,8 @@
901901
<Compile Include="NHSpecificTest\NH3874\IntWrapperType.cs" />
902902
<Compile Include="NHSpecificTest\NH3874\One.cs" />
903903
<Compile Include="NHSpecificTest\NH3874\Two.cs" />
904+
<Compile Include="NHSpecificTest\NH3909\Entity.cs" />
905+
<Compile Include="NHSpecificTest\NH3909\FixtureByCode.cs" />
904906
<Compile Include="NHSpecificTest\NH646\Domain.cs" />
905907
<Compile Include="NHSpecificTest\NH646\Fixture.cs" />
906908
<Compile Include="NHSpecificTest\NH3234\Fixture.cs" />

src/NHibernate/Linq/Visitors/MemberExpressionJoinDetector.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ protected override Expression VisitMemberExpression(MemberExpression expression)
5151
return _joiner.AddJoin(result, key);
5252
}
5353

54+
_hasIdentifier = false;
5455
return result;
5556
}
5657

0 commit comments

Comments
 (0)