File tree 6 files changed +151
-0
lines changed
UnionsubclassPolymorphicFormula
6 files changed +151
-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 =" 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 >
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 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
+ }
You can’t perform that action at this time.
0 commit comments