I have a nvarchar(2000) column in a SQL Server 2005 database, and have mapped this into NHibernate as:
<property name="Query" column="`Query`" type="String" length="2000" not-null="false"/>
The DTO class just presents a string property:
public virtual string Query { get; set; }
If I set the query to a string of > 2000 characters I get an exception from SQL server to the effect of:
"String or binary data would be truncated. The statement has been terminated."
What I want is for this truncation to just happen automatically and silently. I could override the virtual property and force the truncation on the property set, but feel there should be a way to get this behaviour by default, either via the NHibernate mapping or even as a SQL server setting.
Am I missing anything ... I don't want to change the db schema to allow longer strings.