我的数据库由以下列组成:
App Icon, App Title, App Description, Date, Actual Price,
Itunes Link, AppID, UserID, Downloads Count
我需要知道在过去的7天内插入了多少应用,但今天除了Linq查询。我尝试了它,这是我找到的代码,但我无法根据我的需要修改它
var q = from u in entity.Submit_App
where u.Date > DateTime.Now.AddDays(-30) &&
u.Date <= DateTime.Now
group u by EntityFunctions.TruncateTime(u.Date) into g
select new ChartTotal()
{
OrderDate = g.Key,
Total = g.Sum(y => y.GrandTotal)
};
答案 0 :(得分:0)
使用DateTime.Today
获取没有时间的日期。您还可以使用let
关键字引入新的范围变量,以简化您的查询:
var q = from u in entity.Submit_App
let date = EntityFunctions.TruncateTime(u.Date)
where date >= DateTime.Today.AddDays(-7) &&
date < DateTime.Today
group u by date into g
select new ChartTotal {
OrderDate = g.Key,
Total = g.Sum(x => x.GrandTotal)
};