Arnis Lapsa
Arnis Lapsa

Reputation: 47607

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

Upvotes: 6

Views: 1273

Answers (2)

Marc Climent
Marc Climent

Reputation: 9484

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.

Upvotes: 1

Arnis Lapsa
Arnis Lapsa

Reputation: 47607

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

Upvotes: 3

Related Questions