NHibernate and MySql Keywords

吃可爱长大的小学妹 提交于 2019-12-24 19:29:26

问题


Why Nibernate HQL can not handle the following query:

from Deal D where (D.ApprovalDate + INTERVAL 1 Year) < current_timestamp() <  (D.RenewalDate + INTERVAL -1 Year) 

knowing that INTERVAL and YEAR are keywords in MySQL, so this is kind of mixing Sql within Hql (unless Hql can handle date functions like so and I don't know) . The dialect is MySQLDialect

Its perfectly valid to execute this query

  SELECT '2005-01-01' + INTERVAL 1 Year;

回答1:


You can pass the Sql directly in the query using Criteria Query. Something like this

Session.CreateCriteria<Deal>()
.Add(Restrictions.Sql(D.ApprovalDate + " INTERVAL 1 Year < current_timestamp() < " + D.RenewalDate + " INTERVAL -1 Year")

The Restrictions.Sql will pass whatever you give it directly to the database as sql.



来源:https://stackoverflow.com/questions/2660035/nhibernate-and-mysql-keywords

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