我怎样才能在NHibernate中映射一个可为空的枚举? [英] How can I map a nullable enum in NHibernate?
问题描述
$ p $ System.Data.SqlClient.SqlException:转换失败时将
nvarchar值VGS转换为数据类型tinyint。
该属性被定义为
公共虚拟CostContributor? ReplacementContributor {get;私人设置}
和映射是
Map(x => x.ReplacementContributor).CustomTypeIs(typeof(CostContributor?));
我已经尝试了CustomTypeIs和CustomSqlTypeIs的所有组合,包括替换int?或字节?为CostContributor?,但没有任何工作。它可以正常工作,如果我把它作为一个非空类型。
是否有可能在NHibernate中映射一个可为空的枚举?或者这是NHibernate中的一个错误或不支持的功能?
如果我不能做这个工作,我会添加一个未定义的值到我的枚举作为解决方法。
这是 bug已被修正。
I have been unable to persist a nullable enum using NHibernate with Fluent NHibernate configuration. NHibernate attempts to save a string representation of the enum and I get the error
System.Data.SqlClient.SqlException: Conversion failed when converting the
nvarchar value 'VGS' to data type tinyint.
The property is defined as
public virtual CostContributor? ReplacementContributor { get; private set; }
and the mapping is
Map(x => x.ReplacementContributor).CustomTypeIs(typeof(CostContributor?));
I've tried every combination of CustomTypeIs and CustomSqlTypeIs, including substituting int? or byte? for CostContributor?, but nothing has worked. It works fine if I make it a non-nullable type.
Is it possible to map a nullable enum in NHibernate? Or is this a bug or unsupported feature in NHibernate?
If I can't make this work I'm going to add an Undefined value to my enum as a workaround.
This was a bug and it's been fixed.
这篇关于我怎样才能在NHibernate中映射一个可为空的枚举?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!