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 @"\" + ":";
.
精彩评论