2010-03-31 50 views
1

忽略我有许多拥有不同的属性流利,NHibernate的 - 由公约

通常,当这些属性添加到他们被我的自定义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;} 
} 

我与列颜色&组件名称表MyClass的

颜色是一个nvarchar(50),而组件名是一个nvarchar(255)(默认值)

回答

2

行,所以依靠内置 - 将NHibernate.Validators的LengthAttribute绑定到表列的长度似乎不是一个好主意。神奇的是,对于沼泽标准课程来说,它自然会被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); 
     } 
    }