Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Nhibernate generate table with Text field instead of nvarchar(255)

I'm trying to make NHibernate generate my schema/SQL 2008, and using the mapping below it keeps wanting to create an nvarchar(255) column instead of text...any ideas?

    <property name="AnnouncementText" column="AnnouncementText" type="StringClob">
  <column name="AnnouncementText" sql-type="NTEXT"/>
</property>

Thanks!

like image 777
Webjedi Avatar asked May 26 '09 20:05

Webjedi


2 Answers

The problem is specifying the name of the column twice...once I took it and the length out of the property element it worked perfectly

 <property name="AnnouncementText" type="StringClob">
  <column name="AnnouncementText" sql-type="text"/>
</property>
like image 181
Webjedi Avatar answered Oct 07 '22 03:10

Webjedi


I'm used to SQL Server 2005 and the dialect it uses, but I presume you can do something similar. Since nvarchar(n) allows n up to 4000, a value above this will use nvarchar(max).

I presume that SQL Server 2000, which it sounds like you're using, does something similar once you hit the limit. If I read the NHibernate code correctly (NHibernate.Dialect.MsSql2000Dialect..ctor()) you get ntext once you pass 0xFA0 = 4000 characters.

<property name="AnnouncementText" column="AnnouncementText" type="string" length="10000"/>
like image 35
sisve Avatar answered Oct 07 '22 03:10

sisve