流畅的NHibernate - 自动化:允许单个属性为null

我知道这个问题已经多次以类似的形式提出,但没有一个主题可以给我一个问题的具体答案。 我使用Fluent NHibernate和Fluent的自动映射来映射我的域实体。现在,我使用这个约定类来设置所有属性NOT NULL:
public class NotNullColumnConvention : IPropertyConvention
{
    public void Apply(FluentNHibernate.Conventions.Instances.IPropertyInstance instance)
    {
        instance.Not.Nullable();
    }
} 
最大的问题是: 我需要做什么,允许我的实体类的单个属性为NULL? 这是我的一个实体类:
public class Employee : Entity
{
    public virtual string FirstName { get; set; }
    public virtual string LastName { get; set; }
}
我真的很高兴,如果有人能最终帮助我的话!我已输入Google返回页面的所有可能搜索字符串,标记为已访问过... 谢谢, 阿恩 编辑:更改标题...想要允许单个属性为NULL     
已邀请:
创建一个属性:
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class CanBeNullAttribute : Attribute
{
}
一个惯例:
public class CanBeNullPropertyConvention : IPropertyConvention, IPropertyConventionAcceptance
{
    public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
    {
        criteria.Expect(
            x => !this.IsNullableProperty(x)
            || x.Property.MemberInfo.GetCustomAttributes(typeof(CanBeNullAttribute), true).Length > 0);
    }

    public void Apply(IPropertyInstance instance)
    {
        instance.Nullable();
    }

    private bool IsNullableProperty(IExposedThroughPropertyInspector target)
    {
        var type = target.Property.PropertyType;

        return type.Equals(typeof(string)) || (type.IsGenericType && type.GetGenericTypeDefinition().Equals(typeof(Nullable<>)));
    }
}
将属性放在属性的顶部。     

要回复问题请先登录注册