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

I am having a problem when I pass the char ":" from the user interface. NHibernate mistakenly takes it as a named parameter and throws an error, because there is no value for it.

An exception: -

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

Is there any work?

+3
source share
2 answers

You are probably creating the query incorrectly (concatenating strings, maybe?)

All these works:

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

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

SQL LIKE . @"\" + ":";.

0

Source: https://habr.com/ru/post/1739850/


All Articles