Skip to content

NH-3048 #321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ private class MyComponent : IMyCompo
public string Name { get; set; }
}

[Test]
public void CanSpecifyUnsavedValue()
{
//NH-3048
var mapper = new ModelMapper();
mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id, x =>
{
x.UnsavedValue(UnsavedValueType.Any);
}));

var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();

Assert.AreEqual(mapping.RootClasses[0].CompositeId.unsavedvalue, HbmUnsavedValueType.Any);
}

[Test]
public void WhenPropertyUsedAsComposedIdThenRegister()
{
Expand Down
4 changes: 4 additions & 0 deletions src/NHibernate/Mapping/ByCode/ICompositeIdMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public interface IComponentAsIdAttributesMapper : IAccessorPropertyMapper
/// Useful when the property is an interface and you need the mapping to a concrete class mapped as component.
/// </remarks>
void Class(System.Type componentType);

void UnsavedValue(UnsavedValueType unsavedValueType);
}

public interface IComponentAsIdMapper : IComponentAsIdAttributesMapper, IMinimalPlainPropertyContainerMapper { }
Expand All @@ -21,6 +23,8 @@ public interface IComposedIdMapper<TEntity> : IMinimalPlainPropertyContainerMapp
public interface IComponentAsIdAttributesMapper<TComponent> : IAccessorPropertyMapper
{
void Class<TConcrete>() where TConcrete : TComponent;

void UnsavedValue(UnsavedValueType unsavedValueType);
}

public interface IComponentAsIdMapper<TComponent> : IComponentAsIdAttributesMapper<TComponent>, IMinimalPlainPropertyContainerMapper<TComponent>
Expand Down
5 changes: 5 additions & 0 deletions src/NHibernate/Mapping/ByCode/Impl/ComponentAsIdMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public ComponentAsIdMapper(System.Type componentType, MemberInfo declaringTypeMe
accessorPropertyMapper = new AccessorPropertyMapper(declaringTypeMember.DeclaringType, declaringTypeMember.Name, x => id.access = x);
}

public void UnsavedValue(UnsavedValueType unsavedValueType)
{
id.unsavedvalue = (HbmUnsavedValueType)Enum.Parse(typeof(HbmUnsavedValueType), unsavedValueType.ToString());
}

public HbmCompositeId CompositeId
{
get { return id; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public ComponentAsIdCustomizer(IModelExplicitDeclarationsHolder explicitDeclarat
explicitDeclarationsHolder.AddAsPoid(propertyPath.LocalMember);
}

public void UnsavedValue(UnsavedValueType unsavedValueType)
{
CustomizersHolder.AddCustomizer(PropertyPath, (IComponentAsIdAttributesMapper m) => m.UnsavedValue(unsavedValueType));
}

public void Class<TConcrete>() where TConcrete : TComponent
{
CustomizersHolder.AddCustomizer(PropertyPath, (IComponentAsIdAttributesMapper m) => m.Class(typeof(TConcrete)));
Expand Down
16 changes: 16 additions & 0 deletions src/NHibernate/Mapping/ByCode/UnsavedValueType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NHibernate.Mapping.ByCode
{
public enum UnsavedValueType
{
Undefined,

Any,

None,
}
}
1 change: 1 addition & 0 deletions src/NHibernate/NHibernate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@
<Compile Include="Mapping\ByCode\NotFoundMode.cs" />
<Compile Include="Mapping\ByCode\SchemaAction.cs" />
<Compile Include="Mapping\ByCode\TypeExtensions.cs" />
<Compile Include="Mapping\ByCode\UnsavedValueType.cs" />
<Compile Include="Mapping\ByCode\VersionGeneration.cs" />
<Compile Include="Mapping\Collection.cs" />
<Compile Include="Mapping\Column.cs" />
Expand Down