Fluent NHibernate enforce Not Nullable on Foreign Key Reference

后端 未结 2 1167
别那么骄傲
别那么骄傲 2021-01-03 03:06

Just getting my feet wet with some Fluent NHibernate AutoMap conventions, and ran into something I couldn\'t figure out. I assume I\'m just not looking in the right place...

2条回答
  •  佛祖请我去吃肉
    2021-01-03 04:02

    It seems that IPropertyConvention is only called on simple properties of your classes. If your property references another class, you need to use IReferenceConvention too.

    Try this:

    public class FluentConvention : IPropertyConvention, IReferenceConvention  
    {      
        public void Apply(IPropertyInstance instance)
        {          
            instance.Not.Nullable();      
        }
    
        public void Apply(IManyToOneInstance instance)
        {
            instance.Not.Nullable();
        }
    }      
    

提交回复
热议问题