NHibernate Named Query Parameter Numbering @p1 @p2 etc

Posted by IanT8 on Stack Overflow See other posts from Stack Overflow or by IanT8
Published on 2010-06-17T20:28:52Z Indexed on 2010/06/17 20:33 UTC
Read the original article Hit count: 275

Filed under:

A colleague recently ran into a problem where he was passing in a single date parameter to a named query. In the query, the parameter was being used twice, once in an expression and once in a GROUP BY clause. Much to our surprise, we discovered that NHibernate used two variables and sent the single named parameter in twice, as @p1 and @p2. This behaviour caused SQL to fail the query, with the usual "a column in the select clause is not in the group by clause" (I paraphrase ofcourse).

Is this behaviour normal? Can it be changed? Seems to me that if you have a parameter name like :startDate, NHibernate only needs to pass in @p1 no matter how many times you might refer to :startDate in the query.

Any comments?

The problem was worked around by using another sub-query to overcome the SQL parsing error.

© Stack Overflow or respective owner

Related posts about nhibernate