NHibernate:枚举作为继承鉴别符的异常

时间:2016-12-12 10:48:34

标签: c# nhibernate

我的Enum作为我的列的鉴别器类型有问题。我尝试了以下映射,它可以单独作为列映射工作。但是我收到以下错误:"无法将鉴别器值格式化为实体MyEntity"的SQL字符串。

<discriminator column="type" not-null="true" type="NHibernate.Type.EnumStringType`1[MyEnum, MyAssembly]], NHibernate" />
<subclass name="MyInheritanceOne, MyAssembly" discriminator-value="NF-e" />      
<subclass name="MyInheritanceTwo, MyAssembly" discriminator-value="CT-e" />  

MyEnum如下:

public enum MyEnum
{
    [Description("MDF-e")]
    MDFe = 65,
    [Description("NF-e")]
    NFe = 55,
    [Description("NFC-e")]
    NFCe = 58,
    [Description("CT-e")]
    CTe = 57
}

我已经尝试过将&#34;鉴别器价值&#34; enum文字(&#34; NFe&#34;),描述(&#34; NF-e&#34;)和索引(&#34; 58&#34;)但没有成功。如果类型更改为&#34; System.String&#34;然后工作正常。是否可以使用列作为鉴别器?我得到的例外是:

An exception of type 'NHibernate.MappingException' occurred in NHibernate.dll but was not handled in user code. Additional information: Could not format discriminator value to SQL string of entity MyEnum

有人可以帮帮我吗?

谢谢!

NHibernate 3.2.0.4000和.NET Framework 4.0.30319

0 个答案:

没有答案