How to persist an enum using NHibernate

前端 未结 5 1012
有刺的猬
有刺的猬 2020-12-07 20:38

Is there a way to persist an enum to the DB using NHibernate? That is have a table of both the code and the name of each value in the enum.

I want to keep the enum w

5条回答
  •  生来不讨喜
    2020-12-07 21:03

    Why are you guys over complicating this? It is really simple.

    The mapping looks like this:

    
    

    The model property looks like this:

    public virtual OrganizationTypes OrganizationType { get; set; }
    

    The Enum looks like this:

    public enum OrganizationTypes
    {
        NonProfit = 1,
        ForProfit = 2
    }
    

    NHibernate will automatically figure it all out. Why type more than you need????

提交回复
热议问题