Transfers with NHibernate

What is the recommended way to store transfers using NHibernate?

In other words, should the Enum type be used in the model property? it ID (int)? Or a string?

I would like to know in terms of Fluent NHibernate.

+3
source share
2 answers

We had to deal with this at work recently.

We use FluentNhibernate, and for this we have created an agreement:

public class EnumConvention : IPropertyConvention, IConventionAcceptance<IPropertyInspector>
{
    public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
    {
        criteria.Expect(x => x.Property.PropertyType.IsEnum);
    }

    public void Apply(IPropertyInstance instance)
    {
        instance.CustomType(instance.Property.PropertyType);
    }
}

Then you can simply match your property

Map(x => x.Enum);

This is an integer in the database

+4
source

The most common case is to store them as a numeric value. You do not need anything special, just map the property.

( , #). , . . . , GenericEnumMapper NH.

, enum . NH . IMHO, , ( ) .

+2

Source: https://habr.com/ru/post/1744495/


All Articles