0

我需要过滤像这样的记录集

OrderShippedDate - 20 天 <-- 获取所有带有 ShippedDate 20 天前的订单

var orders = ctx.Orders.Where(p => p.OrderShippedDate == 20) <---??? not sure what I need here .ToList();

如何在 EF / LINQ 中进行日期差异?

4

1 回答 1

2

I would suggest you work out your parameters locally, and then pass those in. It's not clear from your description whether you mean exactly 20 days ago, more than 20 days ago, or less than 20 days ago, which makes it hard to give you concrete advice, but if it's "more than 20 days ago" you might use something like:

var upperBound = DateTime.Today.AddDays(-20);
var orders = ctx.Orders.Where(p => p.OrderShippedDate < upperBound);
于 2012-12-07T18:26:23.310 回答