开发者

NHibernate and MySql Keywords

开发者 https://www.devze.com 2022-12-27 11:44 出处:网络
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)

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 (unl开发者_Go百科ess 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;


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号