NHibernate - setting long string as a parameter for query
private void Test()
{
ISession session = sessionFactory.OpenSession();
var query = session.GetNamedQuery("testQuery");
string s = BuildVeryLongString(); // length more that 4000 chracters
query.SetParameter("Param", s, NHibernateUtil.String);
query
.SetResultTransformer(new AliasToBeanResultTransformer(type))
.List<Type>();
}
In the DB-profiler I can see that the type of Param
is nvarchar(4000)
that is not enough. Is there a way to say NHibernate that I'm going to use longer strings?
Assuming Param
is used as a constraint against a mapped property, the query will try to use the correct data type and length for the parameter, according to the mapped property. Does Param
correlate to a property mapped to an nvarchar(max) column? If so, have you set the data length correctly? You should set the datalength on a string column to a length over 4000 (4001 should work), if you want Nhibernate to recognize it as nvarchar(max).
精彩评论