6
我所有的实体和值对象都实现标记接口IEntity
和IValueObject
。我已经设定好之后,被视为组件,像这样:如何使用Fluent NHibernate自动映射组件集合?
public override bool IsComponent(Type type)
{
return typeof(IValueObject).IsAssignableFrom(type);
}
public override bool ShouldMap(Type type)
{
return typeof(IEntity).IsAssignableFrom(type) || typeof(IValueObject).IsAssignableFrom(type);
}
不幸的是,这似乎并没有允许拥有价值对象的集合被automapped作为组件的集合实体。例如:
public class MyEntity : IEntity
{
public IList<MyValueObject> Objects { get; set; }
}
public class MyValueObject : IValueObject
{
public string Name { get; set; }
public string Value { get; set; }
}
有没有什么办法来定义一个惯例,例如,在任何时间IEntity
具有实现IValueObject
的类型的IList
,它将映射我仿佛指定:
HasMany(x => x.Objects)
.Component(x => {
x.Map(m => m.Name);
x.Map(m => m.Value);
});
我不想做的是必须为每个类手动执行这些覆盖,并一次又一次地写出value对象的每个属性。