【问题标题】:NHibernate : Store VARBINARY to MAXNHibernate : 将 VARBINARY 存储到 MAX
【发布时间】:2012-04-26 16:25:04
【问题描述】:

我正在使用以下映射将 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(不流畅)。

【问题讨论】:

    标签: sql-server-2008 nhibernate blob serializable varbinary


    【解决方案1】:

    根据 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)

    【讨论】:

      猜你喜欢
      • 2011-01-29
      • 1970-01-01
      • 1970-01-01
      • 2011-10-01
      • 2014-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多