Using current_timestamp in NHibernate QueryOver syntax

让人想犯罪 __ 提交于 2019-12-04 14:45:41

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();

This will result in the following SQL:

SELECT this_.... FROM [User] this_ WHERE this_.CreatedOn > sysdatetime() ; 

This may not be applicable for your case, but this might work

session.QueryOver<User>()
     .Where(u => u.CreatedOn > DateTime.Now)
     .List();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!