11using System . Linq ;
22using NHibernate . Cfg . MappingSchema ;
3- using NHibernate . DomainModel ;
43using NHibernate . Mapping . ByCode ;
54using NUnit . Framework ;
65
7- namespace NHibernate . Test . NHSpecificTest . NH3363
6+ namespace NHibernate . Test . NHSpecificTest . GH3363
87{
98 /// <summary>
10- /// Fixture using 'by code' mappings
9+ /// Fixture for wrong statement generated when child classes have same propery name but different type.
1110 /// </summary>
12- /// <remarks>
13- /// This fixture is identical to <see cref="Fixture" /> except the <see cref="Entities" /> mapping is performed
14- /// by code in the GetMappings method, and does not require the <c>Mappings.hbm.xml</c> file. Use this approach
15- /// if you prefer.
16- /// </remarks>
1711 [ TestFixture ]
1812 public class ByCodeFixture : TestCaseMappingByCode
1913 {
2014 protected override HbmMapping GetMappings ( )
2115 {
2216 var mapper = new ModelMapper ( ) ;
23-
17+
2418 mapper . Class < Mother > ( rc =>
2519 {
2620 rc . Id ( x => x . Id , m => m . Generator ( Generators . Identity ) ) ;
@@ -30,16 +24,18 @@ protected override HbmMapping GetMappings()
3024 mapper . Subclass < Child1 > ( rc =>
3125 {
3226 rc . Property ( x => x . Name ) ;
33- rc . ManyToOne ( x => x . Thing , m => {
34- m . NotFound ( NotFoundMode . Ignore ) ;
35- m . Column ( "thingId" ) ;
36- } ) ;
27+ rc . ManyToOne ( x => x . Thing , m =>
28+ {
29+ m . NotFound ( NotFoundMode . Ignore ) ;
30+ m . Column ( "thingId" ) ;
31+ } ) ;
3732 rc . DiscriminatorValue ( 1 ) ;
3833 } ) ;
3934 mapper . Subclass < Child2 > ( rc =>
4035 {
4136 rc . Property ( x => x . Name ) ;
42- rc . ManyToOne ( x => x . Thing , m => {
37+ rc . ManyToOne ( x => x . Thing , m =>
38+ {
4339 m . NotFound ( NotFoundMode . Ignore ) ;
4440 m . Column ( "thingId" ) ;
4541 } ) ;
@@ -49,7 +45,7 @@ protected override HbmMapping GetMappings()
4945 {
5046 rc . Id ( x => x . Id , m => m . Generator ( Generators . Assigned ) ) ;
5147 rc . Property ( x => x . Name ) ;
52-
48+
5349 } ) ;
5450 mapper . Class < Thing2 > ( rc =>
5551 {
@@ -65,11 +61,11 @@ protected override void OnSetUp()
6561 using ( var session = OpenSession ( ) )
6662 using ( var transaction = session . BeginTransaction ( ) )
6763 {
68- var t1 = new Thing1 ( ) { Name = "don't care" , Id = "00001" } ;
64+ var t1 = new Thing1 ( ) { Name = "don't care" , Id = "00001" } ;
6965 session . Save ( t1 ) ;
70- var t2 = new Thing2 ( ) { Name = "look for this" , Id = "00002" } ;
66+ var t2 = new Thing2 ( ) { Name = "look for this" , Id = "00002" } ;
7167 session . Save ( t2 ) ;
72- var child1 = new Child1 { Name = "Child1" , Thing = t1 } ;
68+ var child1 = new Child1 { Name = "Child1" , Thing = t1 } ;
7369 session . Save ( child1 ) ;
7470 var child2 = new Child2 { Name = "Child1" , Thing = t2 } ;
7571 session . Save ( child2 ) ;
@@ -99,7 +95,7 @@ public void LookForThingOfTypeThing2()
9995 using ( var session = OpenSession ( ) )
10096 using ( var transaction = session . BeginTransaction ( ) )
10197 {
102- var result = session . Query < Mother > ( ) . Where ( k=> k is Child2 && ( k as Child2 ) . Thing . Id == "00002" ) . ToList ( ) ;
98+ var result = session . Query < Mother > ( ) . Where ( k => k is Child2 && ( k as Child2 ) . Thing . Id == "00002" ) . ToList ( ) ;
10399
104100 Assert . That ( result , Has . Count . EqualTo ( 1 ) ) ;
105101 transaction . Commit ( ) ;
@@ -142,5 +138,4 @@ public void LookForManyToOneByDescr()
142138 }
143139 }
144140 }
145-
146141}
0 commit comments