NHibernate : 存储 VARBINARY 到 MAX

Tap*_*ose 5 nhibernate blob serializable varbinary sql-server-2008

我正在使用以下映射将 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>
Run Code Online (Sandbox Code Playgroud)

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

如果我使用:

<property name="Settings" type="Serializable" length="2147483647">
    <column name="Settings" not-null="true"/>
</property> 
Run Code Online (Sandbox Code Playgroud)

它也被截断为 8000。我使用的是 NHibernate3.2(不流畅)。

Sol*_*zky 4

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

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

本节显示“length”是 <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> 
Run Code Online (Sandbox Code Playgroud)

或者

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

编辑:
这个问题似乎是重复的:
How do I get Fluent nhibernate to create a varbinary(max) field in sql server

但该信息已经有近 3 年历史了,较新版本的 nHibernate 可能已经纠正了这一点(我无法测试这一点)。

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