NHibernate Image Storage - The length of the byte[] value exceeds the length configured

大城市里の小女人 提交于 2019-12-05 02:06:36

I know it's a little late to be posting a reply but I just came across this exact same error. Below was my resolution - hopefully it helps someone else in the future.

I changed:

Map(x => x.ByteArrayProperty);

to:

Map(x => x.ByteArrayProperty).Length(int.MaxValue);

Sigh, sometimes after 2 days of research you just have to post a question to StackOverflow to find the answer right after.

I'm not sure of the underlying reason, but specifying the property directly when mapping was the problem. To resolve the issue I ended up creating a new "BinaryLengthConvention" below.

public class BinaryColumnLengthConvention : IPropertyConvention, IPropertyConventionAcceptance
{
    public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
    {
        criteria.Expect(x => x.Property.PropertyType == typeof(byte[]));
    }

    public void Apply(IPropertyInstance instance)
    {
        instance.Length(2147483647);
        instance.CustomSqlType("varbinary(MAX)");
    }
}

Magically it all started working. Hopefully someone else that searches for that error message finds this useful.

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