开发者

Colon ':' error - Not all named parameters have been set in Nhibernate?

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开发者_C百科 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?


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


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜