nhibernatefluent-nhibernateenumsnhibernate-mapping

Enum parsing doesn't seem to work with Fluent NHibernate


I have a data access class with an Enum called Salutation:

 public enum Salutation
  {
    Unknown = 0,
    Dame = 1,
    etc
    Mr = 5,
    etc
  }

I am peristing the class with NHibernate, and up until this morning I was using .hbm.xml files for mapping. However, I've now switched to using Fluent NHibernate, but loading instances of the class fails with (for example):

[HibernateException: Can't Parse 5 as Salutation]

As you can see, 5 should be parseable as a Salutation (assuming 5 is an int, it's not possible to tell from the error message).

Anyone know what's going on here?

Thanks

David


Solution

  • This is much easier than I thought.

    Map(x => x.WhateverThePropertyNameIs).CustomType(typeof(MyEnumeration));