1

I use the fallowing NHibernate Mapping (NH 3.2) with MS SQL Server 2008 (set MsSql2008Dialect):

<class name="Layout" table="Layout" lazy="false"  >
    <cache usage="read-write"/>
    <id name="Id" column="Id" type="Guid">      
                    <generator class="assigned"/>
    </id>
  <version name="ObjectVersion" column="ObjectVersion"/>
    <property name="Key" column="Key" type="String" length="255" not-null="true"  />
    <property name="Value" column="Value" type="BinaryBlob" length="2147483647"  />
    <property name="Created" column="Created" type="Timestamp" not-null="true" optimistic-lock="false" />
    <property name="CreatedBy" column="CreatedBy" type="String" length="255" not-null="true" optimistic-lock="false" />
    <property name="Changed" column="Changed" type="Timestamp" optimistic-lock="false" />
    <property name="ChangedBy" column="ChangedBy" type="String" length="255" optimistic-lock="false" />
    <many-to-one  name="User" class="User" foreign-key="FK_User_Layout" lazy="proxy" fetch="select">
        <column name="UserId"/>
    </many-to-one>
</class>

The Problem is here, that for the Column Value, NHibernate will create a Field of IMAGE. But I need VarBinary(max). What is wrong with the mapping?

1

2 Answers 2

3

I have the same problem after migration from version 3.1 to 3.2. I think this is a bug. I have explored source code version 3.1 and 3.2 and have found some difference which changed initialization sequence for MsSqlDialect* classes. I fixed it by creating descendant of dialect class and overriding method "RegisterLargeObjectTypeMappings"

public class MyMsSql2008Dialect : MsSql2008Dialect
{
    protected override void RegisterLargeObjectTypeMappings()
    {
        base.RegisterLargeObjectTypeMappings();
        base.RegisterColumnType(DbType.Binary, 2147483647, "VARBINARY(MAX)");
    }
}    
Sign up to request clarification or add additional context in comments.

Comments

2

Try this

<property name="Value">
    <column name="Value" sql-type="varbinary(max)" />
</property>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.