开发者

Mapping custom enum classes with Fluent Nhibernate

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) { }
}


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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜