Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate stored procedures - set parameter sizes?

I'm executing a stored procedure using GetNamedQuery and setting a string parameter using SetString. NHibernate sets the string parameter to be an NVarchar(4000). My string parameter value is actually longer than this and so gets truncated.

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

Edit: neither of my parameters are properties of the enties involved.

like image 459
Pete S Avatar asked Jun 29 '12 14:06

Pete S


1 Answers

Since NHibernate doesn't have enough information to set the parameter length automatically, you have to do it manually.

Example:

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

In this case I'm using StringClob, which would translate to NVARCHAR(max).

like image 180
Diego Mijelshon Avatar answered Oct 26 '22 23:10

Diego Mijelshon