开发者

NHibernate Delete with date arithmatic using HQL

I've looked around and can't find too much. But is it possible to do something like this using HQL in nHibernate:

Session.CreateQuery(@"DELETE FROM MyObject mo WHERE (mo.AlteredDate + mo.ExpiryDetails.ExpiryTimestamp) < :pNow") .SetDateTime("pNow", DateTime.Now);

So basic开发者_开发问答ally I want to delete all MyObjects from the database where the last time the object was altered (mo.AlteredDate - a DateTime) plus an amount of time such as 2 days and 5 hours (ExpiryDetails.ExpiryTimestamp) is less than now.

Or is it best to retrieve the objects and do the caculation in code using the .NET framework?


Super late to answer, but I did something like this & it works:

IQuery query = Session.CreateQuery("select x from OBJECT x where x.DateTimeForCompare > :dateTimeForCompare2");

query.SetDateTime("dateTimeForCompare2", DateTime.Today);

IList<OBJECT> xx = query.List<OBJECT>();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜