NHibernate, SQL Server - enum to int mapping -
i have class has enum type indicating whether message type email or sms. enum type defined:
public enum remindertype { email = 1, sms = 2 } the class utilizes type looks like:
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 try persist entity of type reminder database however, following error:
system.data.sqlclient.sqlexception (0x80131904): conversion failed when converting nvarchar value 'email' data type int. the backing field of type int, i'm not sure why nhibernate trying map string representation default. i'm using fluent nhibernate, , relevant mapping code is:
mappings.override<reminder>(map => { map.map(x => x.type).column("type") }); i'm pretty sure default behavior of nhibernate map enums ints, why not doing in case? i'm using sql server 2005, if matters.
i doing same thing , got working so...
in case employeetype enum class
map(x => x.employeetype, "employeetype_id").customtype(typeof (employeetype));
Comments
Post a Comment