Skip to content

Commit 29cb73b

Browse files
rjpereshazzik
authored andcommitted
Added support for union-sublass and unit tests
1 parent ef6bb9a commit 29cb73b

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

src/NHibernate.Test/MappingByCode/ExplicitMappingTests/BasicMappingOfSimpleClass.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class MyClass
1919
[Test]
2020
public void AbstractClass()
2121
{
22+
//NH-3527
2223
var mapper = new ModelMapper();
2324
mapper.Class<MyClass>(ca =>
2425
{

src/NHibernate.Test/MappingByCode/ExplicitlyDeclaredModelTests/UnionSubclassMappingStrategyTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,23 @@ public void WhenRegisteredAsUnionSubclassThenIsEntity()
7979

8080
Assert.That(inspector.IsEntity(typeof(Inherited1)), Is.True);
8181
}
82+
83+
[Test]
84+
public void SubclassIsAbstract()
85+
{
86+
//NH-3527
87+
var modelMapper = new ModelMapper();
88+
modelMapper.Class<MyClass>(c => { });
89+
modelMapper.UnionSubclass<Inherited1>(c =>
90+
{
91+
c.Abstract(true);
92+
c.Extends(typeof(MyClass));
93+
});
94+
95+
var mappings = modelMapper.CompileMappingForAllExplicitlyAddedEntities();
96+
97+
Assert.IsTrue(mappings.UnionSubclasses[0].@abstract);
98+
Assert.IsTrue(mappings.UnionSubclasses[0].extends == typeof(MyClass).FullName);
99+
}
82100
}
83101
}

src/NHibernate/Mapping/ByCode/IUnionSubclassMapper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public interface IUnionSubclassAttributesMapper : IEntityAttributesMapper, IEnti
66
void Catalog(string catalogName);
77
void Schema(string schemaName);
88
void Extends(System.Type baseType);
9+
void Abstract(bool isAbstract);
910
}
1011

1112
public interface IUnionSubclassMapper : IUnionSubclassAttributesMapper, IPropertyContainerMapper {}
@@ -15,6 +16,8 @@ public interface IUnionSubclassAttributesMapper<TEntity> : IEntityAttributesMapp
1516
void Table(string tableName);
1617
void Catalog(string catalogName);
1718
void Schema(string schemaName);
19+
void Extends(System.Type baseType);
20+
void Abstract(bool isAbstract);
1821
}
1922

2023
public interface IUnionSubclassMapper<TEntity> : IUnionSubclassAttributesMapper<TEntity>, IPropertyContainerMapper<TEntity> where TEntity : class {}

src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/UnionSubclassCustomizer.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ public void Subselect(string sql)
9797
#endregion
9898

9999
#region Implementation of IUnionSubclassAttributesMapper<TEntity>
100+
public void Extends(System.Type baseType)
101+
{
102+
CustomizersHolder.AddCustomizer(typeof(TEntity), (IUnionSubclassAttributesMapper m) => m.Extends(baseType));
103+
}
104+
105+
public void Abstract(bool isAbstract)
106+
{
107+
CustomizersHolder.AddCustomizer(typeof(TEntity), (IUnionSubclassAttributesMapper m) => m.Abstract(isAbstract));
108+
}
100109

101110
public void Table(string tableName)
102111
{

src/NHibernate/Mapping/ByCode/Impl/UnionSubclassMapper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ public void Subselect(string sql)
150150
#endregion
151151

152152
#region Implementation of IUnionSubclassAttributesMapper
153+
public void Abstract(bool isAbstract)
154+
{
155+
classMapping.@abstract = isAbstract;
156+
classMapping.abstractSpecified = true;
157+
}
153158

154159
public void Table(string tableName)
155160
{

0 commit comments

Comments
 (0)