Using current_timestamp in NHibernate QueryOver Syntax

Can I request the use of current_timestamp in any other nhibernate query methods other than SQL and HQL?

I was thinking of creating some type of IUserType DbDateTime class or something else to solve the problem, but I would not know exactly how to do it.

Does anyone have any ideas?

example of what i want:

session.QueryOver<User>() .Where(u => u.CreatedOn > current_timestamp) .List(); 
+3
source share
2 answers

You can use the IProjection and SQL functions in the QueryOver API as follows:

 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() ; 
+2
source

This may not apply to your case, but it may work.

 session.QueryOver<User>() .Where(u => u.CreatedOn > DateTime.Now) .List(); 
0
source

All Articles