Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate : Store VARBINARY to MAX

I am using following mapping to store a Serializable object to 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>

It is generating a varbinary(8000) for column type of the database. How can I make it to use varbinary(max)?

If I use:

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

It is also truncated to 8000. I am using NHibernate3.2(not fluent).

like image 962
Tapas Bose Avatar asked Oct 09 '22 02:10

Tapas Bose


1 Answers

According to the nHibernate documentation, "length" is not an attribute/property of <property> but instead should be used in <column>.

This section shows that "length" is not a part of <property> : http://nhibernate.info/doc/nh/en/index.html#mapping-declaration-property

This section shows that "length" is a part of <column> : http://nhibernate.info/doc/nh/en/index.html#toolsetguide-s1-2

That last section (20.1 and the Table 20.1 Summary) shows that "sql-type" is also part of <column> so try one of these variations:

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

or

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

Edit:
This question seems to be a duplicate of:
How do I get fluent nhibernate to create a varbinary(max) field in sql server

but that information is almost 3 years old and the newer version of nHibernate might have corrected for this (I have no way to test this).

The following page appears to also be the same issue and is much more recent:
Binary Blob truncated to 8000 bytes - SQL Server 2008 / varbinary(max)

like image 73
Solomon Rutzky Avatar answered Oct 13 '22 10:10

Solomon Rutzky