我怎样才能在NHibernate中映射一个可为空的枚举? [英] How can I map a nullable enum in NHibernate?

查看:168
本文介绍了我怎样才能在NHibernate中映射一个可为空的枚举?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经无法使用NHibernate和Fluent NHibernate配置持久化可枚举的枚举。 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆