我需要获取最近的七个日期,并从数据库中为每个日期添加-4小时
我的SQL查询将是:
select DATEADD(hh, -4, [DateColumn]) from mydatabse.dbo.mytable where DATEDIFF(dd, DATEADD(hh, -4, [DateColumn]), getdate()) between 1 and 7 group by DATEADD(hh, -4, [DateColumn])
谁能帮助我将此SQL查询转换为LINQ?
我想您正在使用C#?请查看以下是否满足您的需求:
using System.Data.Entity.SqlServer; from a in mydatabase.mytable let d = SqlFunctions.DateAdd("hh", -4, a.DateColumn) let e = SqlFunctions.DateDiff("dd", d, SqlFunctions.GetDate()) where e >= 1 && e <= 7 group a by d into g select g.Key;