NHibernate Named Query Parameter Numbering @p1 @p2 etc

允我心安 提交于 2019-12-23 18:59:04

问题


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.


回答1:


That can happen, for example, if the DB you are using does not support named parameters, in which case NHibernate uses positional ones, and it copies the value.



来源:https://stackoverflow.com/questions/3065392/nhibernate-named-query-parameter-numbering-p1-p2-etc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!