我正在处理航类页面。现在我的数据库中有一些航类,我想显示它们。 通过此查询,我将显示所选日期的所有航类(asp:calendar 控件):
var destinationFlights =
(from a in db.Flights
where a.DepartureAirportId == depId && a.DestinationAirportId == destId && a.DepartureDate == depDate
join Airports a1 in db.Airports on a.Airports.AirportName equals a1.AirportName
join Airports a2 in db.Airports on a.Airports1.AirportName equals a2.AirportName
select a).ToList();
我想要实现的是,如果我从日历表单中选择日期 (2014-10-10),我希望查询在表中搜索并显示 +-3 天间隔内的所有航类从选定的日期。有什么建议吗?
最佳答案
您只需计算出开始日期和结束日期,然后在 where
子句中使用比较:
var earliest = depDate.AddDays(-3);
var latest = depDate.AddDays(4); // Exclusive
var destinationFlights = ...
where ... && a.DepartureDate >= earliest && a.DepartureDate < latest
...;
关于c# - Linq to Sql 查询,datediff +-3 天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26057310/