Skip to content

Commit eb44257

Browse files
committed
Merge branch 'gh-300'
2 parents 4b88cc1 + 98d24dd commit eb44257

File tree

7 files changed

+63
-0
lines changed

7 files changed

+63
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Linq;
2+
using NHibernate.Cfg.MappingSchema;
3+
using NHibernate.Mapping.ByCode;
4+
using NUnit.Framework;
5+
6+
namespace NHibernate.Test.MappingByCode.IntegrationTests.NH3110
7+
{
8+
[TestFixture]
9+
public class Fixture
10+
{
11+
[Test]
12+
public void CanSetPolymorphism()
13+
{
14+
var mapper = new ModelMapper();
15+
mapper.Class<Entity>(rc =>
16+
{
17+
rc.Polymorphism(PolymorphismType.Explicit);
18+
});
19+
20+
var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
21+
22+
var entity = mapping.RootClasses[0];
23+
Assert.AreEqual(entity.polymorphism, HbmPolymorphismType.Explicit);
24+
}
25+
}
26+
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@
605605
<Compile Include="MappingByCode\IntegrationTests\NH2825\Fixture.cs" />
606606
<Compile Include="MappingByCode\IntegrationTests\NH2825\FixtureByCode.cs" />
607607
<Compile Include="MappingByCode\IntegrationTests\NH2825\Parent.cs" />
608+
<Compile Include="MappingByCode\IntegrationTests\NH3110\Fixture.cs" />
608609
<Compile Include="MappingByCode\IntegrationTests\NH3135\Fixture.cs" />
609610
<Compile Include="MappingByCode\IntegrationTests\NH3135\Models.cs" />
610611
<Compile Include="MappingByCode\IntegrationTests\NH3280\Domain.cs" />

src/NHibernate/Mapping/ByCode/IClassMapper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Linq.Expressions;
33
using System.Reflection;
4+
using NHibernate.Cfg.MappingSchema;
45

56
namespace NHibernate.Mapping.ByCode
67
{
@@ -25,6 +26,7 @@ public interface IClassAttributesMapper : IEntityAttributesMapper, IEntitySqlsMa
2526
void Filter(string filterName, Action<IFilterMapper> filterMapping);
2627
void Where(string whereClause);
2728
void SchemaAction(SchemaAction action);
29+
void Polymorphism(PolymorphismType type);
2830
}
2931

3032
public interface IClassMapper : IClassAttributesMapper, IPropertyContainerMapper
@@ -64,6 +66,7 @@ public interface IClassAttributesMapper<TEntity> : IEntityAttributesMapper, IEnt
6466
void Filter(string filterName, Action<IFilterMapper> filterMapping);
6567
void Where(string whereClause);
6668
void SchemaAction(SchemaAction action);
69+
void Polymorphism(PolymorphismType type);
6770
}
6871

6972
public interface IClassMapper<TEntity> : IClassAttributesMapper<TEntity>, IPropertyContainerMapper<TEntity> where TEntity : class

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ public void Join(string splitGroupId, Action<IJoinMapper> splitMapping)
256256
splitMapping(splitGroup);
257257
}
258258

259+
public void Polymorphism(PolymorphismType type)
260+
{
261+
classMapping.polymorphism = (HbmPolymorphismType) Enum.Parse(typeof(HbmPolymorphismType), type.ToString());
262+
}
259263
#endregion
260264

261265
#region Implementation of IEntityAttributesMapper

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ public void Schema(string schemaName)
116116
CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Schema(schemaName));
117117
}
118118

119+
public void Polymorphism(PolymorphismType type)
120+
{
121+
CustomizersHolder.AddCustomizer(typeof(TEntity), (IClassMapper m) => m.Polymorphism(type));
122+
}
123+
119124
#endregion
120125

121126
#region Implementation of IEntityAttributesMapper
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace NHibernate.Mapping.ByCode
7+
{
8+
/// <summary>
9+
/// The possible types of polymorphism for IClassMapper.
10+
/// </summary>
11+
public enum PolymorphismType
12+
{
13+
/// <summary>
14+
/// Implicit polymorphism
15+
/// </summary>
16+
Implicit,
17+
18+
/// <summary>
19+
/// Explicit polymorphism
20+
/// </summary>
21+
Explicit
22+
}
23+
}

src/NHibernate/NHibernate.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@
354354
<Compile Include="Mapping\ByCode\Impl\DynamicComponentMapper.cs" />
355355
<Compile Include="Mapping\ByCode\Impl\ManyToAnyMapper.cs" />
356356
<Compile Include="Mapping\ByCode\Import.cs" />
357+
<Compile Include="Mapping\ByCode\PolymorphismType.cs" />
357358
<Compile Include="Mapping\ByCode\PropertyGeneration.cs" />
358359
<Compile Include="Mapping\ByCode\PropertyToField.cs" />
359360
<Compile Include="Mapping\ByCode\SimpleModelInspector.cs" />

0 commit comments

Comments
 (0)