我使用nhibernate访问我的数据库,andromda生成我的映射文件.一切正常,只要我没有使用可空数据类型.我想要的是拥有一个类型为Nullables.NHibernate.NullableInt32Type的实体.我的数据库与"int NULL"(SQL Server)类型的列具有对应关系.相应的类也具有正确的数据类型(int?).但是当我尝试获取数据库的值时,我得到一个NHibernate.MappingException:
NHibernate.MappingException:为类型Namespace.SummaryAttribute指定的映射信息无效,请检查映射文件中是否存在属性类型不匹配----> System.InvalidCastException:Die angegebene Umwandlungistungültig.
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping
xmlns="urn:nhibernate-mapping-2.2"
default-cascade="none">
<class
name="Namespace.SummaryAttribute, Core"
table="SUMMARY_ATTRIBUTE"
dynamic-insert="false"
dynamic-update="false"
lazy="true">
<id name="Id" type="Int64" unsaved-value="0">
<column name="ID" sql-type="NUMERIC(19,0)"/>
<generator class="native">
</generator>
</id>
<property name="ShortName" type="String">
<column name="SHORT_NAME" not-null="true" unique="false" sql-type="VARCHAR(255)"/>
</property>
<property name="LongName" type="String">
<column name="LONG_NAME" not-null="true" unique="false" sql-type="VARCHAR(255)"/>
</property>
<property name="Description" type="String">
<column name="DESCRIPTION" not-null="true" unique="false" sql-type="VARCHAR(255)"/>
</property>
<property name="IsVisible" type="Boolean">
<column name="IS_VISIBLE" not-null="true" unique="false" sql-type="BIT"/>
</property>
<property name="DecimalPlaces" type="Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate">
<column name="DECIMAL_PLACES" not-null="false" unique="false" sql-type="INT"/>
</property>
</class>
</hibernate-mapping>
Run Code Online (Sandbox Code Playgroud)
没有属性"DecimalPlaces"一切正常.即使我将属性更改为简单数据类型int. …