我想从我的桌子上获取今天的记录。 我写了以下查询 -
public ICollection<DashboardNotification> GetNotificationOfToday()
{
DateTime todaysDate = DateTime.Now;
DateTime yesterdaysDate = DateTime.Now.AddDays(-1);
db = new BobTheBuilderEntities();
var notificationList = (from n in db.DashboardNotifications.OrderByDescending(n => n.NotificationDateTime)
where (n.NotificationDateTime > yesterdaysDate && n.NotificationDateTime <= todaysDate)
select n).ToList();
return notificationList;
}
但是上面的查询不起作用,导致它也从昨天开始提取记录。
如何解决此问题?
答案 0 :(得分:0)
尝试以下查询
var notificationList = (from n in db.DashboardNotifications.OrderByDescending(n => n.NotificationDateTime)
where (n.NotificationDateTime > yesterdaysDate )
select n).ToList();
答案 1 :(得分:0)
请你试着将昨天的日期作为变量首先声明
var yesterDay = DateTime.Now.AddDays(-1);
var notificationList = (from n in db.DashboardNotifications.OrderByDescending(n => n.NotificationDateTime)
where (n.NotificationDateTime > yesterDay)
select n).ToList();