您需要将NHUtil更新为DateTime:
RegisterFunction("addseconds", new SQLFunctionTemplate(NHibernateUtil.DateTime, "dateadd(second, ?1, ?2)"));否则,您将只处理日期部分。
您的查询很好,您只需将其包装在Projections.Max()中,如下所示:
var q = _session.QueryOver<Event>() .Select(Projections.Max(Projections.SqlFunction( "addseconds", NHibernateUtil.DateTime, Projections.Property<Event>(y => y.DurationInSeconds), Projections.Property<Event>(y => y.StartTime)))) .SingleOrDefault<DateTime>();
我刚刚快速编写了一个测试(与上面的命名不同),它产生了查询:
SELECT max(dateadd(second, this_.DurationInSeconds, this_.SomeDate)) as y0_FROM Employee this_



