NHibernate的 - 设置长字符串作为查询参数 [英] NHibernate - setting long string as a parameter for query

查看:375
本文介绍了NHibernate的 - 设置长字符串作为查询参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结果
我构造查询是这样的:


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>();
}

在DB-探查我可以看到<$ C $的类型C>参数是为nvarchar(4000)这是不够的。有没有办法说NHibernate的,我要去用长字符串?结果
附: DB是MSSQL 2005年结果
提前感谢!

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!

推荐答案

假设参数被用作针对映射属性约束,该查询将尝试使用正确的数据类型和长度为参数,根据对应的属性。是否参数相关映射到一个nvarchar(max)列的属性?如果是这样,你有没有正确设置数据长度?你应该在一个字符串列中的数据长度设定为超过4000的长度(4001应该工作),如果你想NHibernate的将其识别为为nvarchar(最大)。

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

这篇关于NHibernate的 - 设置长字符串作为查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆