开发者

NHibernate - setting long string as a parameter for query

开发者 https://www.devze.com 2023-02-09 19:40 出处:网络
I\'m constructing a 开发者_开发技巧query like this: private void Test() { ISession session = sessionFactory.OpenSession();

I'm constructing a 开发者_开发技巧query like this:

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?

P.S. DB is MSSQL 2005.

Thanks in advance!


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消