I have registered an SQL function in my dialect subclass
RegisterFunction("addseconds", new SQLFunctionTemplate(NHibernateUtil.Date, "dateadd(second, ?1, ?2)"));
which can be used in queries like so
var q = _session.QueryOver<Event>()
.Select(
Projections.SqlFunction(
"addseconds",
NHibernateUtil.Date,
Projections.Property<Event>(x => x.DurationInSeconds),
Projections.Property<Event>(x => x.StartTime)));
producing the SQL
SELECT dateadd(second,
this_.DurationInSeconds,
this_.StartTime) as y0_
FROM [Event] this_
but what I'm really after is
SELECT MAX(dateadd(second,
this_.DurationInSeconds,
this_.StartTime)) as y0_
FROM [Event] this_
unfortunately I can't seem to get SelectMax to take a Projections.SqlFunction. Can it be done?