【发布时间】:2009-05-07 17:41:47
【问题描述】:
我无法使用 NHibernate 和 Fluent NHibernate 配置来持久化一个可为空的枚举。 NHibernate 尝试保存枚举的字符串表示,我得到错误
System.Data.SqlClient.SqlException: Conversion failed when converting the
nvarchar value 'VGS' to data type tinyint.
属性定义为
public virtual CostContributor? ReplacementContributor { get; private set; }
映射是
Map(x => x.ReplacementContributor).CustomTypeIs(typeof(CostContributor?));
我已经尝试了 CustomTypeIs 和 CustomSqlTypeIs 的所有组合,包括替换 int?还是字节? CostContributor?,但没有任何效果。如果我将其设为不可为空的类型,它就可以正常工作。
是否可以在 NHibernate 中映射一个可为空的枚举?或者这是 NHibernate 中的错误或不支持的功能?
如果我无法完成这项工作,我将在我的枚举中添加一个未定义的值作为解决方法。
【问题讨论】:
标签: c# nhibernate fluent-nhibernate