forked from nhibernate/nhibernate-core
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented a couple of tests that demonstrate NH-2354
- Loading branch information
Showing
6 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/NHibernate.Test/UnionsubclassPolymorphicFormula/Company.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace NHibernate.Test.UnionsubclassPolymorphicFormula | ||
{ | ||
public class Company : Party | ||
{ | ||
public override string Name { get { return this.CompanyName; } } | ||
public virtual string CompanyName { get; set; } | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/NHibernate.Test/UnionsubclassPolymorphicFormula/Party.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace NHibernate.Test.UnionsubclassPolymorphicFormula | ||
{ | ||
public abstract class Party | ||
{ | ||
public virtual long Id { get; protected internal set; } | ||
public abstract string Name { get; } | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/NHibernate.Test/UnionsubclassPolymorphicFormula/Party.hbm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" | ||
assembly="NHibernate.Test" | ||
namespace="NHibernate.Test.UnionsubclassPolymorphicFormula"> | ||
|
||
<!-- | ||
Testing the inheritance of the abstract property "Name" | ||
--> | ||
|
||
<!-- PARTY --> | ||
|
||
<class xmlns="urn:nhibernate-mapping-2.2" name="Party" table="`party`" abstract="true"> | ||
<id access="backfield" name="Id"> | ||
<column name="Id" /> | ||
<generator class="sequence"> | ||
<param name="sequence">party_id_seq</param> | ||
</generator> | ||
</id> | ||
|
||
<!-- PERSON --> | ||
|
||
<union-subclass name="Person" table="`person`" extends="Party"> | ||
<property name="Name" access="readonly" formula="first_name || ' ' || last_name" update="false" insert="false"> | ||
</property> | ||
<property name="FirstName"> | ||
<column name="first_name" /> | ||
</property> | ||
<property name="LastName"> | ||
<column name="last_name" /> | ||
</property> | ||
</union-subclass> | ||
|
||
<!-- COMPANY--> | ||
|
||
<union-subclass name="Company" table="`company`" extends="Party"> | ||
<property name="Name" access="readonly" update="false" insert="false"> | ||
<column name="company_name" /> | ||
</property> | ||
<property name="CompanyName"> | ||
<column name="company_name" /> | ||
</property> | ||
</union-subclass> | ||
</class> | ||
|
||
</hibernate-mapping> |
14 changes: 14 additions & 0 deletions
14
src/NHibernate.Test/UnionsubclassPolymorphicFormula/Person.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace NHibernate.Test.UnionsubclassPolymorphicFormula | ||
{ | ||
public class Person : Party | ||
{ | ||
public override string Name { get { return this.FirstName + " " + this.LastName; } } | ||
public virtual string FirstName { get; set; } | ||
public virtual string LastName { get; set; } | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/NHibernate.Test/UnionsubclassPolymorphicFormula/UnionSubclassFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using NUnit.Framework; | ||
using System.Collections; | ||
|
||
namespace NHibernate.Test.UnionsubclassPolymorphicFormula | ||
{ | ||
[TestFixture] | ||
public class UnionSubclassFixture : TestCase | ||
{ | ||
protected override string MappingsAssembly | ||
{ | ||
get { return "NHibernate.Test"; } | ||
} | ||
|
||
protected override IList Mappings | ||
{ | ||
get { return new string[] { "UnionsubclassPolymorphicFormula.Party.hbm.xml" }; } | ||
} | ||
|
||
[Test] | ||
public void QueryOverPersonTest() | ||
{ | ||
using (ISession s = OpenSession()) | ||
{ | ||
using (ITransaction t = s.BeginTransaction()) | ||
{ | ||
var person = new Person | ||
{ | ||
FirstName = "Mark", | ||
LastName = "Mannson" | ||
}; | ||
|
||
s.Save(person); | ||
|
||
var result = s.QueryOver<Party>().Where(p => p.Name == "Mark Mannson").SingleOrDefault(); | ||
|
||
Assert.NotNull(result); | ||
s.Delete(result); | ||
t.Commit(); | ||
} | ||
|
||
} | ||
} | ||
|
||
[Test] | ||
public void QueryOverCompanyTest() | ||
{ | ||
using (ISession s = OpenSession()) | ||
{ | ||
using (ITransaction t = s.BeginTransaction()) | ||
{ | ||
var company = new Company | ||
{ | ||
CompanyName = "Limited", | ||
}; | ||
|
||
s.Save(company); | ||
|
||
var result = s.QueryOver<Party>().Where(p => p.Name == "Limited").SingleOrDefault(); | ||
Assert.NotNull(result); | ||
} | ||
|
||
} | ||
} | ||
} | ||
} |