NHibernate stored procedures - set parameter sizes?

I am executing a stored procedure using GetNamedQuery and setting a string parameter using SetString . NHibernate sets the string parameter to NVarchar(4000) . My string parameter value is actually more than that, and therefore truncation happens.

Is there a way to tell NHibernate to use a longer string type when executing a query? The request is defined in the mapping file as simple. exec dbo.ProcessUploads :courseId, :uploadxml

Edit: none of my parameters are properties of the involved participants.

+4
source share
2 answers

Since NHibernate does not have enough information to automatically set the parameter length, you must do this manually.

Example:

 session.GetNamedQuery("ProcessUploads") .SetParameter("courseId", courseId) .SetParameter("uploadXml", uploadXml, NHibernateUtil.StringClob) .ExecuteUpdate(); 

In this case, I use StringClob , which translates to NVARCHAR(max) .

+10
source

You must show us or check your HBM file for parameters. There you can specify the type of field / property, length ...

Here you can read the official nHibernate documentation

+1
source

All Articles