Basic date/time manipulation in NHiberate query

≡放荡痞女 提交于 2019-12-11 06:56:27

问题


I'm trying to restrict my NHibernate query with some basic date/time manipulation. More specifically, I want to execute the following statement (pseudo-SQL):

select * from article where created_on + lifespan >= sysdate

with:

  • created_on is mapped to a property of type DateTime.
  • lifespan is mapped to a property of type TimeSpan.
  • sysdate is the current date/time (of the database server or ofthe application host, I don't care)

Is there any built-in way to do that by using the Criteria-API or HQL?

return session
  .CreateCriteria<Article>()
  .Add( ? )
  .List<Article>();

回答1:


Since the queries are executed by the server, it needs to support the operations you want to do.

If it does, you'd need to inherit the corresponding Dialect and register the corresponding functions in its constructor.




回答2:


create view activearticle as 
    select * from article 
    where created_on + lifespan >= sysdate


来源:https://stackoverflow.com/questions/2923994/basic-date-time-manipulation-in-nhiberate-query

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