问题
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
with:
created_on
is mapped to a property of typeDateTime
.lifespan
is mapped to a property of typeTimeSpan
.sysdate
is the current date/time (of the database server or ofthe application host, I don't care)
Is there any built-in way to do that by using the Criteria-API or HQL?
return session
.CreateCriteria<Article>()
.Add( ? )
.List<Article>();
回答1:
Since the queries are executed by the server, it needs to support the operations you want to do.
If it does, you'd need to inherit the corresponding Dialect and register the corresponding functions in its constructor.
回答2:
create view activearticle as
select * from article
where created_on + lifespan >= sysdate
来源:https://stackoverflow.com/questions/2923994/basic-date-time-manipulation-in-nhiberate-query