Skip to content

Commit ea68170

Browse files
committed
Merge branch 'acutus-NH-2354'
2 parents 12e8615 + 867640c commit ea68170

File tree

6 files changed

+151
-0
lines changed

6 files changed

+151
-0
lines changed

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,10 @@
12301230
<Compile Include="Unionsubclass\DatabaseKeywordBase.cs" />
12311231
<Compile Include="Unionsubclass\DatabaseKeywordsFixture.cs" />
12321232
<Compile Include="UtilityTest\ArrayHelperTests.cs" />
1233+
<Compile Include="UnionsubclassPolymorphicFormula\Company.cs" />
1234+
<Compile Include="UnionsubclassPolymorphicFormula\Party.cs" />
1235+
<Compile Include="UnionsubclassPolymorphicFormula\Person.cs" />
1236+
<Compile Include="UnionsubclassPolymorphicFormula\UnionSubclassFixture.cs" />
12331237
<Compile Include="UtilityTest\IdentitySetFixture.cs" />
12341238
<Compile Include="UtilityTest\EnumerableExtensionsTests\AnyExtensionTests.cs" />
12351239
<Compile Include="UtilityTest\EnumerableExtensionsTests\FirstExtensionTests.cs" />
@@ -3048,6 +3052,7 @@
30483052
<EmbeddedResource Include="NHSpecificTest\NH3332\Mappings.hbm.xml">
30493053
<SubType>Designer</SubType>
30503054
</EmbeddedResource>
3055+
<EmbeddedResource Include="UnionsubclassPolymorphicFormula\Party.hbm.xml" />
30513056
<EmbeddedResource Include="NHSpecificTest\NH3050\Mappings.hbm.xml" />
30523057
<EmbeddedResource Include="NHSpecificTest\NH2469\Mappings.hbm.xml" />
30533058
<EmbeddedResource Include="NHSpecificTest\NH2033\Mappings.hbm.xml" />
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace NHibernate.Test.UnionsubclassPolymorphicFormula
7+
{
8+
public class Company : Party
9+
{
10+
public override string Name { get { return this.CompanyName; } }
11+
public virtual string CompanyName { get; set; }
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace NHibernate.Test.UnionsubclassPolymorphicFormula
7+
{
8+
public abstract class Party
9+
{
10+
public virtual long Id { get; protected internal set; }
11+
public abstract string Name { get; }
12+
}
13+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
2+
assembly="NHibernate.Test"
3+
namespace="NHibernate.Test.UnionsubclassPolymorphicFormula">
4+
5+
<!--
6+
Testing the inheritance of the abstract property "Name"
7+
-->
8+
9+
<!-- PARTY -->
10+
11+
<class xmlns="urn:nhibernate-mapping-2.2" name="Party" table="`party`" abstract="true">
12+
<id access="backfield" name="Id">
13+
<column name="Id" />
14+
<generator class="hilo" />
15+
</id>
16+
17+
<!-- PERSON -->
18+
19+
<union-subclass name="Person" table="`person`" extends="Party">
20+
<property name="Name" access="readonly" formula="first_name || ' ' || last_name" update="false" insert="false" />
21+
<property name="FirstName">
22+
<column name="first_name" />
23+
</property>
24+
<property name="LastName">
25+
<column name="last_name" />
26+
</property>
27+
</union-subclass>
28+
29+
<!-- COMPANY-->
30+
31+
<union-subclass name="Company" table="`company`" extends="Party">
32+
<property name="Name" access="readonly" update="false" insert="false">
33+
<column name="company_name" />
34+
</property>
35+
<property name="CompanyName">
36+
<column name="company_name" />
37+
</property>
38+
</union-subclass>
39+
</class>
40+
41+
</hibernate-mapping>
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+
using System.Linq;
4+
using System.Text;
5+
6+
namespace NHibernate.Test.UnionsubclassPolymorphicFormula
7+
{
8+
public class Person : Party
9+
{
10+
public override string Name { get { return this.FirstName + " " + this.LastName; } }
11+
public virtual string FirstName { get; set; }
12+
public virtual string LastName { get; set; }
13+
}
14+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using NUnit.Framework;
2+
using System.Collections;
3+
4+
namespace NHibernate.Test.UnionsubclassPolymorphicFormula
5+
{
6+
[TestFixture, Explicit]
7+
public class UnionSubclassFixture : TestCase
8+
{
9+
protected override string MappingsAssembly
10+
{
11+
get { return "NHibernate.Test"; }
12+
}
13+
14+
protected override IList Mappings
15+
{
16+
get { return new string[] { "UnionsubclassPolymorphicFormula.Party.hbm.xml" }; }
17+
}
18+
19+
[Test, KnownBug("NH-2354")]
20+
public void QueryOverPersonTest()
21+
{
22+
using (ISession s = OpenSession())
23+
{
24+
using (ITransaction t = s.BeginTransaction())
25+
{
26+
var person = new Person
27+
{
28+
FirstName = "Mark",
29+
LastName = "Mannson"
30+
};
31+
32+
s.Save(person);
33+
34+
var result = s.QueryOver<Party>().Where(p => p.Name == "Mark Mannson").SingleOrDefault();
35+
36+
Assert.NotNull(result);
37+
s.Delete(result);
38+
t.Commit();
39+
}
40+
41+
}
42+
}
43+
44+
[Test, KnownBug("NH-2354")]
45+
public void QueryOverCompanyTest()
46+
{
47+
using (ISession s = OpenSession())
48+
{
49+
using (ITransaction t = s.BeginTransaction())
50+
{
51+
var company = new Company
52+
{
53+
CompanyName = "Limited",
54+
};
55+
56+
s.Save(company);
57+
58+
var result = s.QueryOver<Party>().Where(p => p.Name == "Limited").SingleOrDefault();
59+
Assert.NotNull(result);
60+
}
61+
62+
}
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)