2010-03-31 88 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); 
     } 
    }