本文介绍了FNhibernate Automap约定非空字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮忙,我如何指示automap对
a列没有null?

Could some one help, how would I instruct automap to have not-null fora column?

public class Paper : Entity
{
    public Paper() { }

            [DomainSignature]
            [NotNull, NotEmpty]
            public virtual string ReferenceNumber { get; set; }

            [NotNull]
            public virtual Int32 SessionWeek { get; set; }
}

但是我收到以下内容:

But I am getting the following:

 <column name="SessionWeek"/>

我知道这可以使用流利地图来完成。但我想知道它在
自动映射的方式。

I know it can be done using fluent-map. but i would like to know it inauto-mapping way.

推荐答案

谢谢。此外,ReferenceConvention需要做参考性能。这是工作的代码:

Thank you. Also, for reference properties ReferenceConvention need to be done. This is the code that works:

public class ColumnNullConvention : IPropertyConvention
{
    public void Apply(IPropertyInstance instance)
    {
        if (instance.Property.MemberInfo.IsDefined(typeof(NotNullAttribute), false))
            instance.Not.Nullable();
    }

}  public class ReferenceConvention : IReferenceConvention
{
    public void Apply(FluentNHibernate.Conventions.Instances.IManyToOneInstance instance)
    {
        instance.Column(instance.Property.Name + "Fk");


        if (instance.Property.MemberInfo.IsDefined(typeof(NotNullAttribute), false))
            instance.Not.Nullable();

    }
}

这篇关于FNhibernate Automap约定非空字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 16:18