Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map SQL Server `varbinary(max)` field with NHibernate ByCode mapping?

I have a class with a property of type byte[] that I would like to map to a varbinary(max) field in SQL Server using the new NHibernate ByCode mapping.

So far, using SchemaAction = SchemaAutoAction.Recreate in order to have NH create the schema, I've ended up with the following (the class property name is "Data"):

  • When mapping is not qualified in any way, I end up with a varbinary(8000) field
  • When mapping is map.Property(x => x.Data, m => m.Length(int.MaxValue)), I end up with an 'image' field (which, according to SQL Server docs, will not be supported in the next release of SQL Server)
  • When mapping is map.Property(x => x.Data, m => m.Type(TypeFactory.GetBinaryType(int.MaxValue)), I end up with a varbinary(8000) field, which just seems wrong

What am I missing?

like image 244
Michael Teper Avatar asked Jul 26 '26 21:07

Michael Teper


1 Answers

I experienced the same problem and this has worked for me.

Property(e => e.Data, m => m.Column(cm => cm.SqlType("varbinary(MAX)")));
like image 114
Alexei Matrosov Avatar answered Jul 29 '26 14:07

Alexei Matrosov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!