[英]How Can I Write a LINQ Query to Get Content Within the Last Seven Days?
我有這個 LINQ 查詢:
Contents.Where(Content => Content.Categories.Contains("top story") And Content.RunDate.Value <= DateTime.Now)
.Distinct()
.OrderByDescending(Content => Content.RunDate)
.Take(4)
我需要修改它,以便它只抓取不超過 7 天的內容。 知道我怎么做嗎?
使用DateTime.Now.AddDays(count)
其中count
甚至可以是負值
Contents.Where(content => content.RunDate.Value >= DateTime.Now.AddDays(-7) &&
content.RunDate.Value <= DateTime.Now)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.