冒号 ':'错误 - 并非所有命名参数都已在 Nhibernate 中设置?

发布于 2024-08-27 12:42:32 字数 234 浏览 3 评论 0原文

每当我从用户界面传递字符“:”时,我都会遇到问题。 NHibernate 将其误认为是命名参数并抛出错误,因为它没有任何值。

例外是:-

并非所有命名参数都已 设置:[%] [从表中选择 COUNT (*) 个 t WHERE t.FirstName LIKE ':%' AND t.ID IN (38, 20)]"

有什么解决办法吗?

I got a problem whenever I pass char ":" from the user interface. NHibernate mistakes it as a named parameter and throws an error, since there isn't any value for it.

Exception is :-

Not all named parameters have been
set: [%] [SELECT COUNT (*) FROM Table
t WHERE t.FirstName LIKE ':%' AND
t.ID IN (38, 20)]"

Is there any work around?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

涫野音 2024-09-03 12:42:32

您可能以错误的方式创建查询(也许是连接字符串?)

所有这些工作:

session.CreateCriteria<Test2>()
       .Add(Restrictions.Like("FirstName", ":%"))
       .UniqueResult<Test2>();

session.CreateQuery("from Test2 where FirstName like :expr")
       .SetParameter("expr", ":%")
       .UniqueResult<Test2>();

You are probably creating the query in a wrong way (concatenating strings, maybe?)

All of these work:

session.CreateCriteria<Test2>()
       .Add(Restrictions.Like("FirstName", ":%"))
       .UniqueResult<Test2>();

session.CreateQuery("from Test2 where FirstName like :expr")
       .SetParameter("expr", ":%")
       .UniqueResult<Test2>();
剩一世无双 2024-09-03 12:42:32

使用 SQL LIKE 时需要转义特殊字符。尝试将参数传递为 @"\" + ":";

You need to escape special characters when using SQL LIKE. Try passing the parameter as @"\" + ":";.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文