My goal is to fetch two values from two tables joined together and perform a comparison which if true, outputs the rows from table 1. The TSQL code below illustrates the query, question is whether there is a way to do the third predicate in the where clause using NHibernate criteria using session.CreateCriteria:
declare @currentSystemTime datetimeoffset = '2015-07-22 18:42:16.1172838 +00:00'
select
inst.ExpiryDate,
ent.DaysToExpiryNotificationStart,
convert(date, dateadd(day, -ent.DaysToExpiryNotificationStart, inst.ExpiryDate)) as NotificationStart,
convert(date, @currentSystemTime) as CurrentSystemTime,
*
from
Instances inst
inner join Entries ent on inst.Entry_id = ent.Id
where
inst.ExpiryDate is not null
and ent.DaysToExpiryNotificationStart is not null
and convert(date, @currentSystemTime) >= convert(date, dateadd(day, -ent.DaysToExpiryNotificationStart, inst.ExpiryDate))
The properties are defined as follows in the entity classes:
public virtual DateTimeOffset? ExpiryDate { get; set; }
public virtual int? DaysToExpiryNotificationStart { get; set; }
I am using Fluent NHibernate to map these. Are manual queries via CreateQuery or CreateSQLQuery the only way to go? If there is an easier way to accomplish this task, I am open. Any help will be appreciated.
Thanks, Shawn