我的所有实体和值对象都实现了标记接口IEntity和IValueObject.我把它们设置为像这样的组件:
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);
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这似乎不允许将具有值对象集合的实体自动化为组件集合.例如:
public class MyEntity : IEntity
{
public IList<MyValueObject> Objects { get; set; }
}
public class MyValueObject : IValueObject
{
public string Name { get; set; }
public string Value { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
有没有办法定义一个约定,这样,只要IEntity有IList一个类型实现IValueObject,它就像我指定的那样被映射:
HasMany(x => x.Objects)
.Component(x => {
x.Map(m => m.Name);
x.Map(m => m.Value); …Run Code Online (Sandbox Code Playgroud) nhibernate components fluent-nhibernate automapping value-objects