Skip to content

Commit a083691

Browse files
rjpereshazzik
authored andcommitted
NH-3048
1 parent 8aaff65 commit a083691

File tree

6 files changed

+46
-0
lines changed

6 files changed

+46
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ private class MyComponent : IMyCompo
2929
public string Name { get; set; }
3030
}
3131

32+
[Test]
33+
public void CanSpecifyUnsavedValue()
34+
{
35+
//NH-3048
36+
var mapper = new ModelMapper();
37+
mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id, x =>
38+
{
39+
x.UnsavedValue(UnsavedValueType.Any);
40+
}));
41+
42+
var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
43+
44+
Assert.AreEqual(mapping.RootClasses[0].CompositeId.unsavedvalue, HbmUnsavedValueType.Any);
45+
}
46+
3247
[Test]
3348
public void WhenPropertyUsedAsComposedIdThenRegister()
3449
{

src/NHibernate/Mapping/ByCode/ICompositeIdMapper.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public interface IComponentAsIdAttributesMapper : IAccessorPropertyMapper
1212
/// Useful when the property is an interface and you need the mapping to a concrete class mapped as component.
1313
/// </remarks>
1414
void Class(System.Type componentType);
15+
16+
void UnsavedValue(UnsavedValueType unsavedValueType);
1517
}
1618

1719
public interface IComponentAsIdMapper : IComponentAsIdAttributesMapper, IMinimalPlainPropertyContainerMapper { }
@@ -21,6 +23,8 @@ public interface IComposedIdMapper<TEntity> : IMinimalPlainPropertyContainerMapp
2123
public interface IComponentAsIdAttributesMapper<TComponent> : IAccessorPropertyMapper
2224
{
2325
void Class<TConcrete>() where TConcrete : TComponent;
26+
27+
void UnsavedValue(UnsavedValueType unsavedValueType);
2428
}
2529

2630
public interface IComponentAsIdMapper<TComponent> : IComponentAsIdAttributesMapper<TComponent>, IMinimalPlainPropertyContainerMapper<TComponent>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public ComponentAsIdMapper(System.Type componentType, MemberInfo declaringTypeMe
2020
accessorPropertyMapper = new AccessorPropertyMapper(declaringTypeMember.DeclaringType, declaringTypeMember.Name, x => id.access = x);
2121
}
2222

23+
public void UnsavedValue(UnsavedValueType unsavedValueType)
24+
{
25+
id.unsavedvalue = (HbmUnsavedValueType)Enum.Parse(typeof(HbmUnsavedValueType), unsavedValueType.ToString());
26+
}
27+
2328
public HbmCompositeId CompositeId
2429
{
2530
get { return id; }

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public ComponentAsIdCustomizer(IModelExplicitDeclarationsHolder explicitDeclarat
1919
explicitDeclarationsHolder.AddAsPoid(propertyPath.LocalMember);
2020
}
2121

22+
public void UnsavedValue(UnsavedValueType unsavedValueType)
23+
{
24+
CustomizersHolder.AddCustomizer(PropertyPath, (IComponentAsIdAttributesMapper m) => m.UnsavedValue(unsavedValueType));
25+
}
26+
2227
public void Class<TConcrete>() where TConcrete : TComponent
2328
{
2429
CustomizersHolder.AddCustomizer(PropertyPath, (IComponentAsIdAttributesMapper m) => m.Class(typeof(TConcrete)));
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace NHibernate.Mapping.ByCode
7+
{
8+
public enum UnsavedValueType
9+
{
10+
Undefined,
11+
12+
Any,
13+
14+
None,
15+
}
16+
}

src/NHibernate/NHibernate.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@
498498
<Compile Include="Mapping\ByCode\NotFoundMode.cs" />
499499
<Compile Include="Mapping\ByCode\SchemaAction.cs" />
500500
<Compile Include="Mapping\ByCode\TypeExtensions.cs" />
501+
<Compile Include="Mapping\ByCode\UnsavedValueType.cs" />
501502
<Compile Include="Mapping\ByCode\VersionGeneration.cs" />
502503
<Compile Include="Mapping\Collection.cs" />
503504
<Compile Include="Mapping\Column.cs" />

0 commit comments

Comments
 (0)