NHibernate 3.0 binary data truncation

NHibernate 3.0.0 has a bug which silently truncates data going into varbinary(MAX) fields to 8000 bytes — not a pleasant one to find in production because your test documents weren’t big enough! This stackoverflow answer contains a workaround for hbm file mappings; translated to FluentNHibernate auto mapping it becomes:

var sessionFactory = Fluently.Configure()
    .Database(/* database config */)
    .Mappings(m => 
            .Override<Document>(map => 
                map.Map(d => d.Data).Length(2147483647))))

The bug is apparently fixed in 3.0.1.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s