Binary Blob truncated to 8000 bytes - SQL Server 2008 / varbinary(max)

怎甘沉沦 提交于 2019-11-26 14:27:00

问题


I have upgraded from Fluent Nhibernate 1.0 with Nhibernate 2.1 to pre- release 1.x with NHibernate 3.0 GA and have hit what I think is a regression, but I want to hear if that's indeed the case.

I am using SQL Server Express 2008 and the MSSQL 2008 dialect and have an Image property of type System.Drawing.Image and I have mapped it like this:

Map (food => food.Image)
 .Length (int.MaxValue)
 .Nullable ();

The Image column in the table is of type varbinary(MAX).

The generated hbm for the property is:

<property name="Image" type="System.Drawing.Image, System.Drawing,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
   <column name="Image" length="2147483647" not-null="false" />
</property>`

However no matter what I do the binary blob is truncated to 8000 bytes when serialized with the current FNH and NH versions. That didn't used to be the case with previous versions.

Ideas of why this is happening and how to fix/workaround it?


回答1:


I too have encountered a similar problem and after much experimentation I noticed that when using Nhibernate to generate my schema to a file the generated column type was always length 8000.

Setting setting CustomSqlType to Varbinary(max) as suggested above made no difference, however, this work around in my FluentMapping seemed to do the trick:

Map(x => x.LogoBytes).CustomType("BinaryBlob").Length(1048576).Nullable();  

The length of course is an arbitrary amount but I think it should be set to something less than int.Max. I am new to Nhibernate so I'm still figuring things out but I'd be interested to know if this helps you.




回答2:


In 3.0.0GA, the following mapping seems to do the trick:

        <property name="Data" type="Serializable" length="2147483647" />



回答3:


This is a regression. I have raised a bug and provided patches at https://nhibernate.jira.com/browse/NH-2484




回答4:


Map(x => x.Image).Length(100000).Not.Nullable();

Add the 'Length(MAXVALUE)' as above and it will work :)




回答5:


Have you tried this?

Map(x => x.Image).CustomSqlType("VARBINARY(MAX)");


来源:https://stackoverflow.com/questions/4584170/binary-blob-truncated-to-8000-bytes-sql-server-2008-varbinarymax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!