5

我正在使用以下映射将 Serializable 对象存储到 SQL Server 2008:

<class name="EMSApplication.Data.Domain.Configuration, EMSApplication.Data" table="ems_Configurations" proxy="EMSApplication.Data.Domain.IConfiguration, EMSApplication.Data" lazy="true">
  <id name="Id" type="System.Int32">
    <column name="Id" not-null="true"/>
    <generator class="native"/>
  </id>
  <property name="Settings" type="Serializable">
    <column name="Settings" not-null="true"/>
  </property>   
</class>

它正在为数据库的列类型生成一个 varbinary(8000)。我怎样才能使它使用 varbinary(max)?

如果我使用:

<property name="Settings" type="Serializable" length="2147483647">
    <column name="Settings" not-null="true"/>
</property> 

它也被截断为 8000。我正在使用 NHibernate3.2(不流利)。

4

1 回答 1

4

根据 nHibernate 文档,“长度”不是 <property> 的属性/属性,而是应该在 <column> 中使用。

本节显示“长度”不是 <property> 的一部分:http: //nhibernate.info/doc/nh/en/index.html#mapping-declaration-property

本节显示“长度”是 <column> 的一部分:http: //nhibernate.info/doc/nh/en/index.html#toolsetguide-s1-2

最后一节(20.1 和表 20.1 总结)表明“sql-type”也是 <column> 的一部分,因此请尝试以下变体之一:

<property name="Settings" type="Serializable">
    <column name="Settings" not-null="true" length="2147483647"/>
</property> 

或者

<property name="Settings" type="Serializable">
    <column name="Settings" not-null="true" sql-type="varbinary(max)"/>
</property> 

编辑:
这个问题似乎是重复的:
如何让流利的 nhibernate 在 sql server 中创建一个 varbinary(max) 字段

但是该信息已经有将近 3 年的历史了,新版本的 nHibernate 可能已经对此进行了纠正(我无法对此进行测试)。

以下页面似乎也是同样的问题,并且是更新的:
Binary Blob truncated to 8000 bytes - SQL Server 2008 / varbinary(max)

于 2012-04-14T18:33:08.210 回答