我正在处理 LINQ 查询以检索本周的所有记录,但是,我需要排除今天和昨天的任何记录。
这是我到目前为止所拥有的:
DateTime startThisWeek = DateFunctions.GetFirstDayOfWeek(DateTime.Now).AddDays(1);
DateTime endOfThisWeek = startThisWeek.AddDays(6);
DateTime today = DateTime.Now;
DateTime yesterday = DateTime.Now.AddDays(-1);
var notificationList =
(from n in db.DashboardNotifications
.OrderByDescending(n => n.NotificationDateTime)
where (n.NotificationDateTime >= startThisWeek &&
n.NotificationDateTime <= endOfThisWeek) &&
(n.NotificationDateTime != today &&
n.NotificationDateTime != yesterday)
select n).ToList();
上面查询的问题是它没有返回正确的记录,它也显示了今天的记录。