开发者

NHibernate create IMAGE instead VarBinary(max)

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" />
  开发者_如何学Go  <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?


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)");
    }
}    


Try this

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜