6

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) { }
}
Arnis Lapsa
  • 45,880
  • 29
  • 115
  • 195

2 Answers2

3

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

Arnis Lapsa
  • 45,880
  • 29
  • 115
  • 195
  • +1 thanks, and for anyone who wants it you can find it here: http://code.google.com/p/codecampserver/source/browse/trunk/src/Infrastructure/EnumerationType.cs – rohancragg Nov 30 '09 at 14:50
  • 1
    This link is invalid. http://code.google.com/p/codecampserver/source/browse/trunk/src/Infrastructure.NHibernate/DataAccess/EnumerationType.cs?spec=svn1063&r=1063 – Quintin Par Jan 04 '10 at 04:10
  • Thanks for fixing it. They changed project structure a bit. – Arnis Lapsa Jan 04 '10 at 06:35
1

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.

Marc Climent
  • 9,434
  • 2
  • 50
  • 55