0
我正在构建一个应用程序使用NHibernate映射的代码,并且我无法映射受保护的属性,当我使用组件映射(相当于hbm复合元素映射)为值对象的集合。NHibernate:映射在组件(复合元素)映射受保护的成员
我能映射单个值对象的实体和组件映射中的受保护属性,它仅仅是映射值对象集合时似乎不受支持的受保护属性。
public class MyEntity
{
public virtual int Id { get; protected set; }
protected virtual MyValueObject MyValueObject { get; set; }
}
public class MyValueObject
{
protected string SomeString { get; set; }
protected ISet<NestedValueObject> NestedValueObjects { get; set; }
// Constructor, Equals/GetHashcode overrides, etc.
}
public class NestedValueObject
{
public string Name { get; set; }
protected DateTime CreatedOn { get; set; } // Audit only property
// Constructor, Equals/GetHashcode overrides, etc.
}
public MyEntityMap()
{
Table("MyEntityTable");
Id(x => x.Id, map =>
{
map.Column("Id");
});
Component<MyValueObject>("MyValueObject", c =>
{
// Protected property maps correctly
c.Property("SomeString", map =>
{
map.NotNullable(true);
});
c.Set<NestedValueObject>("NestedValueObjects", map =>
{
map.Table("NestedValueObjectsTable");
map.Key(k => k.Column("MyEntityId"));
}, r => r.Component(n =>
{
// Public property maps correctly
n.Property(x => x.Name);
// Compilation fail - there is no method that supports protected properties in component mappings
n.Property<DateTime>("CreatedOn", map =>
{
map.NotNullable(true);
});
}));
});
}
这是因为IMinimalPlainPropertyContainerMapper<TContainer>
支持保护遗产,而IComponentElementMapper<TComponent>
没有。
这是有原因吗?值对象应该被允许具有仅用于审计目的的保护属性并且不构成其概念标识的一部分似乎是合理的,并且对于单值对象的组件映射支持保护属性。