我有以下sql,我不知道如何在Linq to Entities中执行DateAdd和IsNull。这甚至可能吗?
Select TOP 1 DateAdd(MINUTE,
(IsNull(AlarmMinutes, 0) * -1) + (IsNull(SnoozeMinutes, 0)),
DueDate)
From Todo
Order By DateAdd(MINUTE,
(IsNull(AlarmMinutes, 0) * -1) + (IsNull(SnoozeMinutes, 0)),
DueDate)
答案 0 :(得分:1)
您可以使用EnitityFunctions.AddMinutes
var date = (from x in context.Todo
let AlarmMinutes = x.AlarmMinutes.HasValue ? x.AlarmMinutes.Value : 0
let SnoozeMinutes= x.SnoozeMinutes.HasValue ? x.SnoozeMinutes.Value : 0
let newDate = EntityFunctions.AddMinutes(x.DueDate, AlarmMinutes*-1 + SnoozeMinutes)
ordeby newDate
select newDate).FirstOrDefault();