NHibernate Pitfalls: Large Strings
This is part of a series of posts about NHibernate Pitfalls. See the entire collection here.
If you want to map large string columns (SQL Server’s VARCHAR(max)/NVARCHAR(max), Oracle’s CLOB/NCLOB) to NHibernate properties, you must specify the StringClobType. This is because the default mapping type for string columns, StringType, does not support large strings (>4000 characters).
If you also want to generate the database from the model, you should also specify the native column type. For SQL Server:
1: <property column="`LARGE_STRING`" name="LargeString" type="StringClob" sql-type="NVARCHAR(max)" />
And for Oracle:
1: <property column="`LARGE_STRING`" name="LargeString" type="StringClob" sql-type="NCLOB" />
Of course, the .NET class remains the same, whatever the underlying NHibernate mapping type is:
1: public virtual String LargeString { get; set; }