2012-04-14 86 views
4

我使用以下映射到一個序列化對象存儲到SQL Server 2008:NHibernate的:存儲VARBINARY到MAX

<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

根據nHibernate文檔,「長度」不是<屬性>的屬性/屬性,而應該用於<列>。

本節表明,「長度」是不<屬性>的一部分: http://nhibernate.info/doc/nh/en/index.html#mapping-declaration-property

本節表明,「長度」是<柱>的一部分: http://nhibernate.info/doc/nh/en/index.html#toolsetguide-s1-2

即最後一節(20.1和表20.1總結)顯示「sql-type」也是<列>的一部分,因此請嘗試下列其中一個變體:

<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> 

編輯:
這個問題似乎是一個重複:
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)

+0

非常感謝你... – 2012-04-14 18:53:09

+0

隨時隨地......很高興它的工作:) – 2012-04-14 18:58:18

相關問題