Skip to content

Commit 20b6f49

Browse files
committed
Fix mapping
1 parent 74f9bb0 commit 20b6f49

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/NHibernate.Test/NHSpecificTest/NH2319/Fixture.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void ShouldBeAbleToFindChildrenByName()
3333
}
3434
}
3535

36-
[Test, Ignore("Does not work")]
36+
[Test]
3737
public void ShouldBeAbleToPerformComplexFiltering()
3838
{
3939
using (var session = OpenSession())
@@ -48,7 +48,6 @@ public void ShouldBeAbleToPerformComplexFiltering()
4848
.Where(x => x.Name == "Piter")
4949
.SelectMany(x => x.GrandChildren)
5050
.Select(x => x.Id)
51-
//.ToList()
5251
.Count();
5352

5453
Assert.That(filtered, Is.EqualTo(2));
@@ -139,34 +138,39 @@ protected override void OnSetUp()
139138
Name = "Jack",
140139
Parent = parent1
141140
};
141+
parent1.Children.Add(child1);
142142
child1Id = (Guid) session.Save(child1);
143143

144144
var child2 = new Child
145145
{
146146
Name = "Piter",
147147
Parent = parent1
148148
};
149+
parent1.Children.Add(child2);
149150
session.Save(child2);
150151

151152
var grandChild1 = new GrandChild
152153
{
153154
Name = "Kate",
154155
Child = child2
155156
};
157+
child2.GrandChildren.Add(grandChild1);
156158
session.Save(grandChild1);
157159

158160
var grandChild2 = new GrandChild
159161
{
160162
Name = "Mary",
161163
Child = child2
162164
};
165+
child2.GrandChildren.Add(grandChild2);
163166
session.Save(grandChild2);
164167

165168
var child3 = new Child
166169
{
167170
Name = "Jack",
168171
Parent = parent2
169172
};
173+
parent2.Children.Add(child3);
170174
session.Save(child3);
171175

172176
session.Flush();

src/NHibernate.Test/NHSpecificTest/NH2319/Model.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@ class Parent
77
{
88
public virtual Guid Id { get; set; }
99
public virtual string Name { get; set; }
10-
public virtual ICollection<Child> Children { get; set; }
10+
public virtual ICollection<Child> Children { get; set; } = new List<Child>();
1111
}
1212

1313
class Child
1414
{
1515
public virtual Parent Parent { get; set; }
1616
public virtual Guid Id { get; set; }
1717
public virtual string Name { get; set; }
18-
public virtual ICollection<Child> GrandChildren { get; set; }
18+
public virtual ICollection<GrandChild> GrandChildren { get; set; } = new List<GrandChild>();
1919
}
2020
class GrandChild
2121
{
2222
public virtual Child Child { get; set; }
2323
public virtual Guid Id { get; set; }
2424
public virtual string Name { get; set; }
25-
public virtual ICollection<GrandChild> Children { get; set; }
2625
}
2726
}

src/NHibernate/Mapping/ByCode/ModelMapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,9 +1240,9 @@ private void MapIdBag(MemberInfo member, PropertyPath propertyPath, System.Type
12401240
{
12411241
System.Type collectionElementType = GetCollectionElementTypeOrThrow(propertiesContainerType, member, propertyType);
12421242
ICollectionElementRelationMapper cert = DetermineCollectionElementRelationType(member, propertyPath, collectionElementType);
1243-
if(cert is OneToManyRelationMapper)
1243+
if (cert is OneToManyRelationMapper)
12441244
{
1245-
throw new NotSupportedException("id-bag does not suppot one-to-many relation");
1245+
throw new NotSupportedException("id-bag does not support one-to-many relation");
12461246
}
12471247
propertiesContainer.IdBag(member, collectionPropertiesMapper =>
12481248
{

0 commit comments

Comments
 (0)