How to store a non truncated varchar(max) string with NHibernate and Fluent NHibernate

12,299

Solution 1

It would appear that this is an old problem which is now resurfacing in NHibernate 3.x builds; you can read about the workarounds here.

Note: I have updated the original link I posted as it was outdated.

Solution 2

This mapping should work:

<property name="TheProperty" type="StringClob">
  <column name="TheColumn" sql-type="nvarchar(max)" />
</property>

Just look for the fluent equivalent.

Solution 3

DanP's link is broken. The updated link is:

http://www.primordialcode.com/blog/post/nhibernate-prepare_sql-considerations-mapping-long-string-fields

Share:
12,299
Nicolas Cadilhac
Author by

Nicolas Cadilhac

Owner of VisualHint. Developer of Smart PropertyGrid.Net (doc here), the best custom PropertyGrid for .Net, and Smart FieldPackEditor.Net (DateTimePicker, TimeSpanEditor, IPAddressEditor, LatLongEditor and other field based editors). Currently developing: Coludik, a web platform for board games players (to share their games), PlantCatching, a web platform for gardeners, Keyxpat, a windows keyboard tool to get instant access to diacritics and special characters. Vol en Sim, a local service in Montreal to let people learn to fly on a hyper realistic flight simulator.

Updated on July 11, 2022

Comments

  • Nicolas Cadilhac
    Nicolas Cadilhac almost 2 years

    My DB schema has a string as a varchar(max). I have read the other questions concerning setting Length to more than 4000 or 8000 so that it really generates a (n)varchar(max) in the mapping but when I use Length(10000) in my mapping class, the hbm file actually shows length="10000" and if I save an entity with more than 10000 chars, it is actually truncated to exactly 10000 chars.

    I don't want any truncation.

    (using NH3-alpha2 and FNH trunk)