Is it possible to request the usage of current_timestamp in any other nhibernate query methods except for SQL and HQL?
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.
Anyone have any ideas?
example of what I want:
session.QueryOver<User>()
.Where(u => u.CreatedOn > current_timestamp)
.List();
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();
来源:https://stackoverflow.com/questions/6155454/using-current-timestamp-in-nhibernate-queryover-syntax