Fluent NHibernate enforce Not Nullable on Foreign Key Reference

后端 未结 2 1161
别那么骄傲
别那么骄傲 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:12

    You can override the auto-mapped properties as part of your AutoMap in Fluenttly.Configure().

    So you can do this:

    .Override(map => map.References(x => x.Group).Not.Nullable())
    

    It's not exactly convenient if you have a lot of classes that need this though.

    Edit: You can also specify the override in a class that implements IAutoMappingOverride like so:

        public class JobMappingOverride : IAutoMappingOverride
        {
                public void Override(AutoMapping mapping)
                {
                        mapping.References(x => x.Group).Not.Nullable();
                }
        }
    

    and include it like so:

        .UseOverridesFromAssemblyOf()
    

    This would keep your fluent configuration a little cleaner.

提交回复
热议问题