Fluent nhibernate Fluent NHibernate-组件属性被约定忽略

Fluent nhibernate Fluent NHibernate-组件属性被约定忽略,fluent-nhibernate,components,attributes,convention,Fluent Nhibernate,Components,Attributes,Convention,我有一个具有许多属性的组件,这些属性具有各种属性 通常,当这些属性被添加到普通的旧域对象时,它们会被我的自定义AttributeConventions拾取 对于组件属性,它们不是。这些需要额外的接线吗 e、 g 我得到了一个表MyClass,其中包含Colour和ComponentName列 颜色是一个nvarchar(50),而ComponentName是一个nvarchar(255)(默认值)好的,因此依赖于绑定NHibernate的内置魔法。验证程序长度根据表列的长度来确定属性似乎不是一个

我有一个具有许多属性的组件,这些属性具有各种属性

通常,当这些属性被添加到普通的旧域对象时,它们会被我的自定义AttributeConventions拾取

对于组件属性,它们不是。这些需要额外的接线吗

e、 g

我得到了一个表MyClass,其中包含Colour和ComponentName列


颜色是一个nvarchar(50),而ComponentName是一个nvarchar(255)(默认值)

好的,因此依赖于绑定NHibernate的内置魔法。验证程序长度根据表列的长度来确定属性似乎不是一个好主意。神奇的是,对于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);
        }
    }
公共类长度约定:AttributePropertyConvention
{
受保护的覆盖无效应用(LengthAttribute属性,IPropertyInstance实例)
{
//替代默认的列长度
if(attribute.Max!=default(int))instance.Length(attribute.Max);
}
}
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);
        }
    }