NHibernate的:存储VARBINARY到MAX
问题描述:
我使用以下映射到一个序列化对象存储到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(不流畅)。
答
根据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)
非常感谢你... – 2012-04-14 18:53:09
随时随地......很高兴它的工作:) – 2012-04-14 18:58:18