我想查詢一個有多行的表,每個表有一個timestamp
,每隔10分鐘發送一次數據。我想找到任何丟失的數據,這是一開始那裏沒有一個timestamp
等於未來十年分鐘間隔,就像這樣:NHibernate QueryOver SQLFunction where where子句
select a.[timestamp]
from [table] as a
where not exists (select 1
from [table] as b
where a.[id] = b.[id]
and b.[timestamp] = dateadd(mi, 10, a.[timestamp]))
order by a.[timestamp]
我有這到目前爲止,但我看不出如何構建查詢,讓我做b [時間戳] = DATEADD(MI,10,[時間戳])在上面的查詢:
Table tableAlias = null;
IList<DateTimeOffset> dateTimeOffsets = session.QueryOver(() => tableAlias)
.WithSubquery
.WhereNotExists(QueryOver.Of<Table>()
.Where(x => x.Id == tableAlias.Id)
.And(Restrictions.Eq(Projections.SqlFunction("addminutes",
NHibernateUtil.DateTimeOffset,
new[]
{
Projections.Property("Timestamp"),
Projections.Constant(10)
}),
<insert timestamp property again here>))
.Select(Projections.Constant(1)))
.Select(x => x.Timestamp)
.List<DateTimeOffset>();
我不能讓我的頭一輪的限制上sqlfuntion部分 - Nhibernate
只是不會讓我做sqlfunction和我的時間戳的比較。
我希望我在正確的軌道上面的代碼,但請糾正我,如果我完全把我在解決這一嘗試......
親切的問候
+1我通常使用存在子句的id字段select ...然後NH不必爲常量(1)創建多餘的參數。 – dotjoe