Tritac (Master) Fluent NHibernate nvarchar(max) fields truncated to 4000 characters

Fluent NHibernate nvarchar(max) fields truncated to 4000 characters

15 februari 2017  |  Developer

Recently we noticed large text (nvarchar(max)) fields were being truncated to 4000 characters. Apparently this is an issue with NHibernate 3+ and MS Sql Server. The solution is to map these fields like this in Fluent NHibernate: from

Map(x => x.Description);

to

Map(x => x.Description).CustomType("StringClob").CustomSqlType("nvarchar(max)");

You can read more about it here: http://www.primordialcode.com/blog/post/nhibernate-prepare_sql-considerations-mapping-long-string-fields and here for the full discussion: http://zvolkov.com/blog/post/2009/10/28/NHibernate-parameter-sizes-controversy.aspx