File tree Expand file tree Collapse file tree 6 files changed +158
-0
lines changed
UnionsubclassPolymorphicFormula Expand file tree Collapse file tree 6 files changed +158
-0
lines changed Original file line number Diff line number Diff line change 1230
1230
<Compile Include =" Unionsubclass\DatabaseKeywordBase.cs" />
1231
1231
<Compile Include =" Unionsubclass\DatabaseKeywordsFixture.cs" />
1232
1232
<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" />
1233
1237
<Compile Include =" UtilityTest\IdentitySetFixture.cs" />
1234
1238
<Compile Include =" UtilityTest\EnumerableExtensionsTests\AnyExtensionTests.cs" />
1235
1239
<Compile Include =" UtilityTest\EnumerableExtensionsTests\FirstExtensionTests.cs" />
3048
3052
<EmbeddedResource Include =" NHSpecificTest\NH3332\Mappings.hbm.xml" >
3049
3053
<SubType >Designer</SubType >
3050
3054
</EmbeddedResource >
3055
+ <EmbeddedResource Include =" UnionsubclassPolymorphicFormula\Party.hbm.xml" />
3051
3056
<EmbeddedResource Include =" NHSpecificTest\NH3050\Mappings.hbm.xml" />
3052
3057
<EmbeddedResource Include =" NHSpecificTest\NH2469\Mappings.hbm.xml" />
3053
3058
<EmbeddedResource Include =" NHSpecificTest\NH2033\Mappings.hbm.xml" />
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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 =" sequence" >
15
+ <param name =" sequence" >party_id_seq</param >
16
+ </generator >
17
+ </id >
18
+
19
+ <!-- PERSON -->
20
+
21
+ <union-subclass name =" Person" table =" `person`" extends =" Party" >
22
+ <property name =" Name" access =" readonly" formula =" first_name || ' ' || last_name" update =" false" insert =" false" >
23
+ </property >
24
+ <property name =" FirstName" >
25
+ <column name =" first_name" />
26
+ </property >
27
+ <property name =" LastName" >
28
+ <column name =" last_name" />
29
+ </property >
30
+ </union-subclass >
31
+
32
+ <!-- COMPANY-->
33
+
34
+ <union-subclass name =" Company" table =" `company`" extends =" Party" >
35
+ <property name =" Name" access =" readonly" update =" false" insert =" false" >
36
+ <column name =" company_name" />
37
+ </property >
38
+ <property name =" CompanyName" >
39
+ <column name =" company_name" />
40
+ </property >
41
+ </union-subclass >
42
+ </class >
43
+
44
+ </hibernate-mapping >
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Text ;
5
+ using NUnit . Framework ;
6
+ using System . Collections ;
7
+
8
+ namespace NHibernate . Test . UnionsubclassPolymorphicFormula
9
+ {
10
+ [ TestFixture ]
11
+ public class UnionSubclassFixture : TestCase
12
+ {
13
+ protected override string MappingsAssembly
14
+ {
15
+ get { return "NHibernate.Test" ; }
16
+ }
17
+
18
+ protected override IList Mappings
19
+ {
20
+ get { return new string [ ] { "UnionsubclassPolymorphicFormula.Party.hbm.xml" } ; }
21
+ }
22
+
23
+ [ Test ]
24
+ public void QueryOverPersonTest ( )
25
+ {
26
+ using ( ISession s = OpenSession ( ) )
27
+ {
28
+ using ( ITransaction t = s . BeginTransaction ( ) )
29
+ {
30
+ var person = new Person
31
+ {
32
+ FirstName = "Mark" ,
33
+ LastName = "Mannson"
34
+ } ;
35
+
36
+ s . Save ( person ) ;
37
+
38
+ var result = s . QueryOver < Party > ( ) . Where ( p => p . Name == "Mark Mannson" ) . SingleOrDefault ( ) ;
39
+
40
+ Assert . NotNull ( result ) ;
41
+ s . Delete ( result ) ;
42
+ t . Commit ( ) ;
43
+ }
44
+
45
+ }
46
+ }
47
+
48
+ [ Test ]
49
+ public void QueryOverCompanyTest ( )
50
+ {
51
+ using ( ISession s = OpenSession ( ) )
52
+ {
53
+ using ( ITransaction t = s . BeginTransaction ( ) )
54
+ {
55
+ var company = new Company
56
+ {
57
+ CompanyName = "Limited" ,
58
+ } ;
59
+
60
+ s . Save ( company ) ;
61
+
62
+ var result = s . QueryOver < Party > ( ) . Where ( p => p . Name == "Limited" ) . SingleOrDefault ( ) ;
63
+ Assert . NotNull ( result ) ;
64
+ }
65
+
66
+ }
67
+ }
68
+ }
69
+ }
You can’t perform that action at this time.
0 commit comments