Skip to content

Commit c3861e5

Browse files
authored
Merge branch 'master' into NH-3951
2 parents 81e84ab + 1c05dcf commit c3861e5

23 files changed

+651
-77
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ Since you now have a failing test case, it should be straight-forward to step in
8282

8383
Once you've made changes to the NHibernate code base, you'll want to ensure that you haven't caused any previously passing tests to fail. The easiest way to check this is to select option D from the build menu, ensure the root tree node is selected, then press run to have all the tests run.
8484

85+
Please note that some tests assume a case insensitive accent sensitive database when performing string comparison. Some tests assume SQL user locales to be en-US. They will fail otherwise. With SQL Server, collation with supplementary characters (\_SC suffix on collation name) are no supported by legacy tests on "text" types.
86+
8587
## Submit a Pull Request
8688

8789
Be sure to link to the JIRA issue in your GitHub pull request. Also, go back to your JIRA issue and link to the pull request.

Contributor Guide.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,12 @@ <h2>Implementing the Bug Fix or Improvement</h2>
132132
Since you now have a failing test case, it should be straight-forward to step into NHibernate to attempt to ascertain what the problem is. While this may seem daunting at first, feel free to give it a go. It's just code afterall. :)
133133

134134
<h3>Ensure All Tests Pass</h3>
135-
136-
Once you've made changes to the NHibernate code base, you'll want to ensure that you haven't caused any previously passing tests to fail. The easiest way to check this is to select option D from the build menu, ensure the root tree node is selected, then press run to have all the tests run.
135+
<p>
136+
Once you've made changes to the NHibernate code base, you'll want to ensure that you haven't caused any previously passing tests to fail. The easiest way to check this is to select option D from the build menu, ensure the root tree node is selected, then press run to have all the tests run.
137+
</p>
138+
<p>
139+
Please note that some tests assume a case insensitive accent sensitive database when performing string comparison. Some tests assume SQL user locales to be en-US. They will fail otherwise. With SQL Server, collation with supplementary characters (_SC suffix on collation name) are no supported by legacy tests on "text" types.
140+
</p>
137141

138142
<h2>Submit a Pull Request</h2>
139143

src/NHibernate.Test/Linq/WhereTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,19 @@ public void CanUseCompareInQuery(Expression<Func<Product, bool>> expression, int
795795
}
796796

797797

798+
[Test(Description = "NH-3665")]
799+
public void SelectOnCollectionReturnsResult()
800+
{
801+
var result = db.Animals.Select(x => new
802+
{
803+
x.Children
804+
}).FirstOrDefault();
805+
806+
Assert.That(result, Is.Not.Null);
807+
Assert.That(result.Children, Is.Not.Empty);
808+
}
809+
810+
798811
private static List<object[]> CanUseCompareInQueryDataSource()
799812
{
800813
return new List<object[]>
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
using NHibernate.Cfg.MappingSchema;
2+
using NHibernate.Mapping.ByCode;
3+
using System;
4+
using System.Collections;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using NUnit.Framework;
8+
9+
namespace NHibernate.Test.MappingByCode.MappersTests
10+
{
11+
public class ComponentWithBagOfNestedComponentsTests : TestCase
12+
{
13+
public class OwnedItem
14+
{
15+
public virtual string NameOnClient { get; set; }
16+
}
17+
class Owner
18+
{
19+
private Lazy<IList<OwnedItem>> _ownedItems = new Lazy<IList<OwnedItem>>(() => new List<OwnedItem>());
20+
21+
public virtual long Id { get; set; }
22+
23+
public virtual IList<OwnedItem> OwnedItems
24+
{
25+
get { return _ownedItems.Value; }
26+
set { _ownedItems = new Lazy<IList<OwnedItem>>(() => value); }
27+
}
28+
}
29+
30+
class OwnerChildOne : Owner
31+
{
32+
}
33+
34+
class OwnerChildTwo: Owner
35+
{
36+
}
37+
38+
public class Intermediate
39+
{
40+
private Lazy<IList<OwnedItem>> _children = new Lazy<IList<OwnedItem>>(() => new List<OwnedItem>());
41+
public virtual IList<OwnedItem> Children
42+
{
43+
get { return _children.Value; }
44+
set { _children = new Lazy<IList<OwnedItem>>(() => value); }
45+
}
46+
}
47+
48+
public class OwnerWithIntermediate
49+
{
50+
public virtual long Id { get; set; }
51+
public virtual Intermediate Intermediate { get; set; }
52+
}
53+
54+
protected override IList Mappings
55+
{
56+
get
57+
{
58+
// We can perform these tests without
59+
// creating a data schema
60+
return new string[0];
61+
}
62+
}
63+
64+
[Test]
65+
public void BagIsPropertyOfEntity()
66+
{
67+
var mapper = new ModelMapper();
68+
mapper.Class<Owner>(classMapper =>
69+
{
70+
classMapper.Id(p => p.Id);
71+
classMapper.Bag<OwnedItem>
72+
(
73+
parent => parent.OwnedItems,
74+
bagPropertyMapper =>
75+
{
76+
bagPropertyMapper.Table("Child");
77+
bagPropertyMapper.Key(k => k.Column("Parent_Id"));
78+
},
79+
r => r.Component(
80+
child =>
81+
{
82+
child.Property
83+
(
84+
c => c.NameOnClient,
85+
pm =>
86+
{
87+
pm.Column("NameInDatabase");
88+
}
89+
);
90+
}
91+
)
92+
);
93+
});
94+
var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();
95+
96+
HbmBag hbmBag = mappings
97+
.Items.Cast<HbmClass>()
98+
.Single()
99+
.Properties.Cast<HbmBag>()
100+
.Single();
101+
102+
Assert.That(hbmBag.Item, Is.InstanceOf<HbmCompositeElement>());
103+
HbmCompositeElement childElement = (HbmCompositeElement)hbmBag.Item;
104+
Assert.That(childElement.Properties.Count(), Is.EqualTo(1));
105+
HbmProperty propertyMapping = childElement.Properties.Cast<HbmProperty>().Single();
106+
Assert.That(propertyMapping.Name, Is.EqualTo("NameOnClient"));
107+
Assert.That(propertyMapping.Columns.Count(), Is.EqualTo(1));
108+
Assert.That(propertyMapping.Columns.Single().name, Is.EqualTo("NameInDatabase"));
109+
}
110+
111+
[Test]
112+
public void BagIsPropertyOfComponent()
113+
{
114+
var mapper = new ModelMapper();
115+
mapper.Class<OwnerWithIntermediate>(classMapper =>
116+
{
117+
classMapper.Id(p => p.Id);
118+
classMapper.Component(
119+
p => p.Intermediate,
120+
componentMapper =>
121+
componentMapper.Bag<OwnedItem>
122+
(
123+
intermediate => intermediate.Children,
124+
bagPropertyMapper =>
125+
{
126+
bagPropertyMapper.Table("Child");
127+
bagPropertyMapper.Key(k => k.Column("Parent_Id"));
128+
},
129+
r => r.Component(child =>
130+
child.Property
131+
(
132+
c => c.NameOnClient,
133+
pm =>
134+
{
135+
pm.Column("NameInDatabase");
136+
}
137+
)
138+
)
139+
)
140+
);
141+
});
142+
143+
var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();
144+
145+
HbmBag hbmBag = mappings
146+
.Items.Cast<HbmClass>()
147+
.Single()
148+
.Properties.Cast<HbmComponent>()
149+
.Single()
150+
.Properties.Cast<HbmBag>()
151+
.Single();
152+
153+
Assert.That(hbmBag.Item, Is.InstanceOf<HbmCompositeElement>());
154+
HbmCompositeElement childElement = (HbmCompositeElement)hbmBag.Item;
155+
Assert.That(childElement.Properties.Count(), Is.EqualTo(1));
156+
HbmProperty propertyMapping = childElement.Properties.Cast<HbmProperty>().Single();
157+
Assert.That(propertyMapping.Name, Is.EqualTo("NameOnClient"));
158+
Assert.That(propertyMapping.Columns.Count(), Is.EqualTo(1));
159+
Assert.That(propertyMapping.Columns.Single().name, Is.EqualTo("NameInDatabase"));
160+
}
161+
162+
[Test]
163+
public void PropertyCustomizerDifferentiatesBetweenChildClasses()
164+
{
165+
var mapper = new ModelMapper();
166+
mapper.Class<OwnerChildOne>(classMapper =>
167+
{
168+
classMapper.Id(p => p.Id);
169+
classMapper.Bag<OwnedItem>
170+
(
171+
parent => parent.OwnedItems,
172+
bagPropertyMapper =>
173+
{
174+
bagPropertyMapper.Table("ChildOne");
175+
bagPropertyMapper.Key(k => k.Column("Parent_Id"));
176+
},
177+
r => r.Component(
178+
child =>
179+
{
180+
child.Property
181+
(
182+
c => c.NameOnClient,
183+
pm =>
184+
{
185+
pm.Column("OwnerChildOne_CustomColumnName");
186+
}
187+
);
188+
}
189+
)
190+
);
191+
});
192+
mapper.Class<OwnerChildTwo>(classMapper =>
193+
{
194+
classMapper.Id(p => p.Id);
195+
classMapper.Bag<OwnedItem>
196+
(
197+
parent => parent.OwnedItems,
198+
bagPropertyMapper =>
199+
{
200+
bagPropertyMapper.Table("ChildTwo");
201+
bagPropertyMapper.Key(k => k.Column("Parent_Id"));
202+
},
203+
r => r.Component(
204+
child =>
205+
{
206+
child.Property
207+
(
208+
c => c.NameOnClient,
209+
pm =>
210+
{
211+
pm.Column("OwnerChildTwo_CustomColumnName");
212+
}
213+
);
214+
}
215+
)
216+
);
217+
});
218+
219+
var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();
220+
221+
222+
HbmBag bag1 = mappings
223+
.Items.Cast<HbmClass>()
224+
.Where(c => c.Name == typeof(OwnerChildOne).FullName)
225+
.Single()
226+
.Properties.Cast<HbmBag>()
227+
.Single();
228+
229+
HbmCompositeElement childElement1 = (HbmCompositeElement)bag1.Item;
230+
HbmProperty propertyMapping1 = childElement1.Properties.Cast<HbmProperty>().Single();
231+
Assert.That(propertyMapping1.Columns.Single().name, Is.EqualTo("OwnerChildOne_CustomColumnName"));
232+
233+
HbmBag bag2 = mappings
234+
.Items.Cast<HbmClass>()
235+
.Where(c => c.Name == typeof(OwnerChildTwo).FullName)
236+
.Single()
237+
.Properties.Cast<HbmBag>()
238+
.Single();
239+
240+
HbmCompositeElement childElement2 = (HbmCompositeElement)bag2.Item;
241+
HbmProperty propertyMapping2 = childElement2.Properties.Cast<HbmProperty>().Single();
242+
Assert.That(propertyMapping2.Columns.Single().name, Is.EqualTo("OwnerChildTwo_CustomColumnName"));
243+
}
244+
245+
246+
}
247+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Collections.Generic;
2+
using NUnit.Framework;
3+
4+
namespace NHibernate.Test.NHSpecificTest.NH3757
5+
{
6+
[TestFixture]
7+
public class Fixture : BugTestCase
8+
{
9+
protected override void OnTearDown()
10+
{
11+
using (ISession s = OpenSession())
12+
{
13+
using (ITransaction tx = s.BeginTransaction())
14+
{
15+
s.CreateSQLQuery("delete from EntityName").ExecuteUpdate();
16+
tx.Commit();
17+
}
18+
}
19+
}
20+
21+
[Test]
22+
public void ShouldBePossibleToHaveComponentInEntityNameMappedEntity()
23+
{
24+
using (ISession session = OpenSession())
25+
using (ITransaction transaction = session.BeginTransaction())
26+
{
27+
var e1 = new Dictionary<string, object>();
28+
e1["Money"] = new Money { Amount = 100m, Currency = "USD" };
29+
session.Save("EntityName", e1);
30+
31+
session.Flush();
32+
transaction.Commit();
33+
}
34+
}
35+
}
36+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.NH3757">
3+
4+
<class entity-name="EntityName">
5+
<id name="Id" type="Int32" generator="native" />
6+
<component name="Money" class="Money">
7+
<property name="Amount" type="decimal"/>
8+
<property name="Currency" type="string"/>
9+
</component>
10+
</class>
11+
12+
</hibernate-mapping>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace NHibernate.Test.NHSpecificTest.NH3757
2+
{
3+
public class Money
4+
{
5+
public virtual decimal Amount { get; set; }
6+
7+
public virtual string Currency { get; set; }
8+
}
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace NHibernate.Test.NHSpecificTest.NH3952
5+
{
6+
class Entity
7+
{
8+
public virtual Guid Id { get; set; }
9+
public virtual string Name { get; set; }
10+
public virtual Guid? ParentId { get; set; }
11+
public virtual ISet<Entity> Children { get; set; }
12+
public virtual string[] Hobbies { get; set; }
13+
}
14+
}

0 commit comments

Comments
 (0)