I have a class that has an enumeration type indicating whether the message type is Email or Sms. The type of listing is defined:
public enum ReminderType { Email = 1, Sms = 2 }
The class that uses this type is as follows:
public class Reminder : EntityBase { public virtual string Origin { get; set; } public virtual string Recipient { get; set; } public virtual ReminderType Type { get; set; } public virtual Business Business { get; set; } public virtual DateTime Created { get; set; } public Reminder() { Created = DateTime.UtcNow; } }
When I try to save an entity of type Reminder in the database, I get the following error:
System.Data.SqlClient.SqlException (0x80131904): Conversion failed when converting the nvarchar value 'Email' to data type int.
The backing field is of type int
, so I'm not sure why NHibernate is trying to match the default string representation. I am using Fluent NHibernate, and the corresponding mapping code:
mappings.Override<Reminder>(map => { map.Map(x => x.Type).Column("Type") });
I am sure that the default behavior of NHibernate is to display enums as ints, so why is this not the case in this case? I am using SQL Server 2005 if that matters.
Chris source share