我有一个具有许多属性的组件,这些属性具有不同的属性
通常,当这些属性被添加到普通旧域对象中时,它们会被我的自定义AttributeConventions拾取。
对于零部件特性,则不是。这些需要一些额外的布线吗?
例如:
public class Component
{
[Length(Max=50)]
public virtual string Name {get; set;}
}
public class MyClass
{
public virtual Component Component {get; set;}
[Length(Max=50)]
public virtual string Color {get; set;}
}我得到了一个包含Color和ComponentName列的表MyClass
Color是nvarchar(50),而ComponentName是nvarchar(255) (默认值)
发布于 2010-03-31 21:56:00
因此,依靠内置的魔术将NHibernate.Validators LengthAttribute绑定到您的表列的长度似乎不是一个好主意。神奇之处在于,对于bog标准类,这会被Fluent自然地接受。为了强制它,我创建了自己的约定来处理它:
public class LengthConvention : AttributePropertyConvention<LengthAttribute>
{
protected override void Apply(LengthAttribute attribute, IPropertyInstance instance)
{
// override the default column length
if (attribute.Max != default(int)) instance.Length(attribute.Max);
}
}https://stackoverflow.com/questions/2552196
复制相似问题