5

I need to map ntext column of a table using the mapping by code feature in NHibernate 3.2, so that it doesn't get truncated to 4000 characters.

What do I neet to change in the following example? "Notes" is the property which has ntext type in sql table:

Property(emp => emp.Notes);

Note: Please don't mix it with fluent NHibernate or hbm file mapping.

Baig
  • 1,489
  • 1
  • 25
  • 41

3 Answers3

4

So, I solved the problem as following:

Property(emp => emp.Notes, map => map.Column(col => col.SqlType("ntext")));

Actually, all what we need to do is: tell the NHibernate mapper the actual type of the column in sql. :)

The solution comes from here as pointed by jbl.

Community
  • 1
  • 1
Baig
  • 1,489
  • 1
  • 25
  • 41
1

Maybe you can try this, which should also work for nvarchar(max) columns :

Property(emp => emp.Notes, m => m.Type(NHibernateUtil.StringClob));

Hope this will help

jbl
  • 15,179
  • 3
  • 34
  • 101
  • It doesn't work since it expects type of "Notes" to be nvarchar(MAX) instead of ntext. – Baig Feb 01 '13 at 10:43
  • 1
    @Baig ok, thx. I hope this can be of some help http://devio.wordpress.com/2012/02/24/mssql-legacy-data-types-in-nhibernate-mapping-bycode-conformist/ – jbl Feb 01 '13 at 10:50
0

Try:

Property(emp => emp.Notes, mapinfo => mapinfo.Lenth(someHighValue));

If the length provided is larger than what can fit in a varchar, NHibernate will switch to a different character type.

Oskar Berggren
  • 5,583
  • 1
  • 19
  • 36