Skip to content

Commit cc9ff7d

Browse files
NH-1904 - public properties cannot have the same name with different case, test case and fix for struct components
1 parent 9491f57 commit cc9ff7d

File tree

5 files changed

+86
-14
lines changed

5 files changed

+86
-14
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,19 @@ public class Invoice
99

1010
protected virtual DateTime issued { get; set; }
1111
}
12+
13+
public class InvoiceWithAddress : Invoice
14+
{
15+
public virtual Address BillingAddress { get; set; }
16+
}
17+
18+
public struct Address
19+
{
20+
public string Line { get; set; }
21+
public string line { get; set; }
22+
public string Line2 { get; set; }
23+
public string City { get; set; }
24+
public string ZipCode { get; set; }
25+
public string Country { get; set; }
26+
}
1227
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections;
3+
using NUnit.Framework;
4+
5+
namespace NHibernate.Test.NHSpecificTest.NH1904
6+
{
7+
[TestFixture]
8+
public class StructFixture : BugTestCase
9+
{
10+
protected override IList Mappings =>
11+
new string[]
12+
{
13+
"NHSpecificTest." + BugNumber + ".StructMappings.hbm.xml"
14+
};
15+
16+
[Test]
17+
public void ExecuteQuery()
18+
{
19+
using (ISession session = OpenSession())
20+
using (ITransaction transaction = session.BeginTransaction())
21+
{
22+
var invoice = new InvoiceWithAddress
23+
{
24+
Issued = DateTime.Now,
25+
BillingAddress = new Address { Line = "84 rue du 22 septembre", City = "Courbevoie", ZipCode = "92400", Country = "France" }
26+
};
27+
session.Save(invoice);
28+
transaction.Commit();
29+
}
30+
31+
using (ISession session = OpenSession())
32+
{
33+
var invoices = session.CreateCriteria<Invoice>().List<Invoice>();
34+
}
35+
}
36+
37+
protected override void OnTearDown()
38+
{
39+
base.OnTearDown();
40+
using (ISession session = OpenSession())
41+
{
42+
session.CreateQuery("delete from InvoiceWithAddress").ExecuteUpdate();
43+
session.Flush();
44+
}
45+
}
46+
}
47+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
3+
assembly="NHibernate.Test"
4+
namespace="NHibernate.Test.NHSpecificTest.NH1904">
5+
6+
<class name="InvoiceWithAddress">
7+
<id name="ID" type="Int32">
8+
<generator class="hilo" />
9+
</id>
10+
11+
<property name="Issued" type="DateTime" />
12+
13+
<component name="BillingAddress">
14+
<property name="Line"/>
15+
<property name="Line2"/>
16+
<property name="City"/>
17+
<property name="ZipCode"/>
18+
<property name="Country"/>
19+
</component>
20+
</class>
21+
22+
</hibernate-mapping>

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@
742742
<Compile Include="NHSpecificTest\EntityWithUserTypeCanHaveLinqGenerators\FooExample.cs" />
743743
<Compile Include="NHSpecificTest\EntityWithUserTypeCanHaveLinqGenerators\IExample.cs" />
744744
<Compile Include="Insertordering\NH3931Entities.cs" />
745+
<Compile Include="NHSpecificTest\NH1904\StructFixture.cs" />
745746
<Compile Include="NHSpecificTest\NH3247\Entity.cs" />
746747
<Compile Include="NHSpecificTest\NH3247\Fixture.cs" />
747748
<Compile Include="NHSpecificTest\NH3386\Entity.cs" />
@@ -3251,6 +3252,7 @@
32513252
<EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
32523253
</ItemGroup>
32533254
<ItemGroup>
3255+
<EmbeddedResource Include="NHSpecificTest\NH1904\StructMappings.hbm.xml" />
32543256
<EmbeddedResource Include="Insertordering\FamilyModel\Mappings.hbm.xml" />
32553257
<EmbeddedResource Include="Insertordering\AnimalModel\Mappings.hbm.xml" />
32563258
<EmbeddedResource Include="NHSpecificTest\NH3247\Mappings.hbm.xml" />

src/NHibernate/Properties/BasicPropertyAccessor.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,8 @@ internal static BasicSetter GetSetterOrNull(System.Type type, string propertyNam
130130
return null;
131131
}
132132

133-
// According to http://msdn.microsoft.com/EN-US/library/kz0a8sxy%28v=VS.110,d=hv.2%29.aspx
134-
// the assumption articulated in the comment following "if(type.IsValueType)" is wrong at least since .NET 2.0!
135-
// This part of the code has beed changed twice to fix the following Issues in order: NH-1728 then NH-1904
136-
// As it stands now the implementation prevents AliasToBeanTransformer from finding the correct property
137-
// on a class if the dialect returns column names in a different case than expected.
138-
139133
BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
140134

141-
if (type.IsValueType)
142-
{
143-
// the BindingFlags.IgnoreCase is important here because if type is a struct, the GetProperty method does
144-
// not ignore case by default. If type is a class, it _does_ ignore case... we're better off explicitly
145-
// stating that casing should be ignored so we get the same behavior for both structs and classes
146-
bindingFlags = bindingFlags | BindingFlags.IgnoreCase;
147-
}
148-
149135
PropertyInfo property = type.GetProperty(propertyName, bindingFlags);
150136

151137
if (property != null && property.CanWrite)

0 commit comments

Comments
 (0)