Mapping custom enum classes with Fluent Nhibernate

一世执手 提交于 2019-12-07 03:30:42

问题


Reading some posts from Jimmy Boggard and wondering - how exactly is it possible to map those beasts with fluent nhibernate?

How mapping would look like for this?

public class EmployeeType : Enumeration{
    public static readonly EmployeeType 
     Manager = new EmployeeType(0, "Manager"),
     Servant = new EmployeeType(1, "Servant"),
     AssistantToTheRegionalManager = new EmployeeType
       (2, "Assistant to the Regional Manager");

    private EmployeeType() { }
    private EmployeeType(int value, string displayName) : 
        base(value, displayName) { }
}

回答1:


Ah... it was easy. In CodeCampServer - there's a generic EnumerationType class. Idea is simple - we just need to wrap our domain model enumeration value object with EnumerationType in order to map it as integer (or anything else if necessary).




回答2:


You can also create derive from IUserType and specify how to store an retrieve the information from a specific column on the database, serializing and deserializing the enumeration.

Check this article for a simple explanation of the basics of IUserType.



来源:https://stackoverflow.com/questions/1593773/mapping-custom-enum-classes-with-fluent-nhibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!