NHiberate查询中的基本日期/时间操作 [英] Basic date/time manipulation in NHiberate query

查看:110
本文介绍了NHiberate查询中的基本日期/时间操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过一些基本的日期/时间操作来限制 NHibernate 查询.更具体地说,我要执行以下语句(伪SQL):

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

具有:

  • created_on映射到类型为DateTime的属性.
  • lifespan映射到类型为TimeSpan的属性.
  • sysdate是当前日期/时间(我不在乎数据库服务器或应用程序主机的日期/时间)
  • 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)

是否有使用 Criteria-API HQL 的内置方法?

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

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

推荐答案

由于查询是由服务器执行的,因此它需要支持您要执行的操作.

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

如果这样做,则需要继承相应的Dialect,并在其构造函数中注册相应的功能.

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

这篇关于NHiberate查询中的基本日期/时间操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆