Skip to content

Commit 3b7fdfc

Browse files
committed
NH-3860 - Add missing EntityName to IManyToOneMapper
Fixes #1182
1 parent dfbcdc9 commit 3b7fdfc

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

src/NHibernate.Test/MappingByCode/MappersTests/ManyToOneMapperTest.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ public void AssignCascadeStyle()
3737
mapper.Cascade(Mapping.ByCode.Cascade.Persist | Mapping.ByCode.Cascade.Remove);
3838
Assert.That(hbm.cascade.Split(',').Select(w => w.Trim()), Contains.Item("persist").And.Contains("delete"));
3939
}
40+
41+
[Test]
42+
public void AssignEntityName()
43+
{
44+
var hbmMapping = new HbmMapping();
45+
var hbm = new HbmManyToOne();
46+
IManyToOneMapper mapper = new ManyToOneMapper(null, hbm, hbmMapping);
47+
mapper.EntityName("MyEntity");
48+
Assert.That(hbm.EntityName, Is.EqualTo("MyEntity"));
49+
}
4050

4151
[Test]
4252
public void CanSetAccessor()

src/NHibernate/Mapping/ByCode/IManyToOneMapper.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using System;
2+
using NHibernate.Mapping.ByCode.Impl;
3+
14
namespace NHibernate.Mapping.ByCode
25
{
36
public interface IManyToOneMapper : IEntityPropertyMapper, IColumnsMapper
@@ -10,7 +13,6 @@ public interface IManyToOneMapper : IEntityPropertyMapper, IColumnsMapper
1013
/// Useful when the property is an interface and you need the mapping to a concrete class mapped as entity.
1114
/// </remarks>
1215
void Class(System.Type entityType);
13-
1416
void Cascade(Cascade cascadeStyle);
1517
void NotNullable(bool notnull);
1618
void Unique(bool unique);
@@ -24,5 +26,29 @@ public interface IManyToOneMapper : IEntityPropertyMapper, IColumnsMapper
2426
void ForeignKey(string foreignKeyName);
2527
void PropertyRef(string propertyReferencedName);
2628
void NotFound(NotFoundMode mode);
29+
//6.0 TODO: Uncomment
30+
//void EntityName(string entityName);
31+
}
32+
33+
//6.0 TODO: Remove
34+
public static class ManyToOneMapperExtensions
35+
{
36+
public static void EntityName(this IManyToOneMapper mapper, string entityName)
37+
{
38+
switch (mapper)
39+
{
40+
case KeyManyToOneMapper m:
41+
m.EntityName(entityName);
42+
break;
43+
case ManyToOneMapper m:
44+
m.EntityName(entityName);
45+
break;
46+
default:
47+
throw new ArgumentException(
48+
"Only mappers of type 'KeyManyToOneMapper' and 'ManyToOneMapper' are supported, got " +
49+
mapper.GetType().FullName,
50+
nameof(mapper));
51+
}
52+
}
2753
}
2854
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public void Class(System.Type entityType)
4646
_manyToOne.@class = entityType.GetShortClassName(_mapDoc);
4747
}
4848

49+
public void EntityName(string entityName)
50+
{
51+
_manyToOne.entityname = entityName;
52+
}
53+
4954
public void Cascade(Cascade cascadeStyle)
5055
{
5156
// not supported by HbmKeyManyToOne

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public void Class(System.Type entityType)
4343
_manyToOne.@class = entityType.GetShortClassName(_mapDoc);
4444
}
4545

46+
public void EntityName(string entityName)
47+
{
48+
_manyToOne.entityname = entityName;
49+
}
50+
4651
public void Cascade(Cascade cascadeStyle)
4752
{
4853
_manyToOne.cascade = cascadeStyle.ToCascadeString();

0 commit comments

Comments
 (0)