在NHibernate QueryOver语法中使用current_timestamp [英] Using current_timestamp in NHibernate QueryOver syntax
本文介绍了在NHibernate QueryOver语法中使用current_timestamp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以请求在除SQL和HQL之外的任何其他nhibernate查询方法中使用current_timestamp?
Is it possible to request the usage of current_timestamp in any other nhibernate query methods except for SQL and HQL?
我当时想制作某种类型的DbDateTime的IUserType类或某种东西来解决该问题,但不知道确切如何实现.
I was thinking of making some type of IUserType class of DbDateTime or something in order to solve the problem, but wouldn't know exactly how to accomplish it.
有人有什么主意吗?
我想要的例子:
session.QueryOver<User>()
.Where(u => u.CreatedOn > current_timestamp)
.List();
推荐答案
您可以在QueryOver API中使用IProjection和SQL函数,如下所示:
You can use IProjection and SQL functions in the QueryOver API like this:
var result = session.QueryOver<User>()
.Where(Restrictions.GtProperty(
Projections.Property<User>(u => u.CreatedOn),
Projections.SqlFunction("current_timestamp", new NHibernate.Type.TimestampType())))
.List();
这将导致以下SQL:
SELECT this_.... FROM [User] this_ WHERE this_.CreatedOn > sysdatetime() ;
这篇关于在NHibernate QueryOver语法中使用current_timestamp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文