The title asks it all. In the database I have legacy data that contains titles of documents that have spaces such as “Title Holder” and so on. I want to be able to map these directly to an enum with Fluent NHibernate but I am encountering parsing errors. I have been unable to find any indication of a custom converter I can use, are there any recommendations someone can make?
My mapping looks like this.
Map(x => x.DocumentName).Nullable().CustomSqlType("varchar(50)");
You are going to need to implement your own NHibernate IUserType and the bulk of your logic will be in the NullSafeGet() and NullSafeSet() methods.
You’ll also need to create your own internal enum to string mapping. You could use a dictionary that would hold the string as the key and the enum value as the value and so your logic would basically revolve around looking up values in that dictionary to convert from a string to an enum and vice versa. Another option could be to use an attribute to decorate each of your enum values with the string version of it’s name and then at runtime do conversion with reflection…
Here are some examples of creating a custom IUserType: ( The first link below should really point you in the right direction )