0

我想从我的表中获取今天的记录。我写了以下查询 -

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;
        }

在此处输入图像描述

但是上面的查询不起作用,因为它也从昨天获取记录。

如何解决这个问题?

4

2 回答 2

0

尝试以下查询

var notificationList = (from n in db.DashboardNotifications.OrderByDescending(n => n.NotificationDateTime)
                                    where (n.NotificationDateTime > yesterdaysDate )
                                    select n).ToList();
于 2013-02-12T05:53:55.573 回答
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();
于 2013-02-12T06:17:55.807 回答