I currently have an issue whereby we are trying to save some XML via an NHibernate mapping, which works fine, except when the XML reaches a certain length. The mapping looks something like this:
Property(x => x.Expression, c =>
{
c.NotNullable(true);
c.Column(m => m.SqlType("xml"));
});
The exception being thrown is:
The length of the string value exceeds the length configured in the mapping/parameter.
Obviously its telling me that the string is too long, although as its an XML mapping I wouldn’t have thought this would be a problem? Saving the XML directly into the SQL Server database via an insert works fine as expected so it looks like the issue is with the NHibernate mapping. Does anyone have any ideas?
Trying changing the mapping to the following:
And then your domain object to use the
XmlDocumentinstead of a string.It seems that NHibernate doesn’t always correctly map XML to a string, especially if it’s a long one.
If you want to be a little more LINQy, you can use an
XDocumentwith theNHibernateUtil.XDoc, although I’ve not tried them myself.