C# 从给定的时间段检索数据

C# 从给定的时间段检索数据,c#,C#,我正在尝试获取过去两周创建的项目列表。我可以检索14个项目,但我想从14天的项目。我的代码如下所示。我对这门语言还不熟悉,我想我已经修好了,但仍然有一个问题。任何帮助都会得到安抚 public ActionResult SolaceHistory() { var model = new SolaceHistoryList(); model.Statuses = OnlineGivingContext.log_SolaceStatus.OrderByDes

我正在尝试获取过去两周创建的项目列表。我可以检索14个项目,但我想从14天的项目。我的代码如下所示。我对这门语言还不熟悉,我想我已经修好了,但仍然有一个问题。任何帮助都会得到安抚

public ActionResult SolaceHistory()
    {

        var model = new SolaceHistoryList();
        model.Statuses = OnlineGivingContext.log_SolaceStatus.OrderByDescending(s => s.DateCreated).Take(14).ToList();
        return View(model);
    }
使用下面的函数

public ActionResult SolaceHistory()
    {
var Criteria=DateTime.Now.AddDays(-14);
        var model = new SolaceHistoryList();
        model.Statuses = OnlineGivingContext.log_SolaceStatus.OrderByDescending(s => s.DateCreated.Date >= Criteria.Date).ToList();
        return View(model);
    }

无法解决我的问题

提示:使用
Where
执行筛选。想想你真正想要过滤的是什么。更大的提示:考虑如何构造一个“截止日期”,这样你就可以找到“代码> S.DeCeReDe> >代码…>代码>……在哪里(x= > x.DeCeReTea> =开始)<代码>哪里<代码>开始>代码>大概是代码> DATETIME.UTcNo.AddDays(-14)?我之前尝试过使用它,但它给了我aSystem.NotSupportedException Message=指定的类型成员“Date”在LINQ to实体中不受支持。仅支持初始值设定项、实体成员和实体导航属性。Source=StackTrace:您是否使用syetem.linq名称空间?
     {
        var Criteria = DateTime.Today.AddDays(-14);
        var model = new SolaceHistoryList();
        model.Statuses = OnlineGivingContext.log_SolaceStatus
            .Where(st => st.DateCreated >= Criteria).
            OrderByDescending(s => s.DateCreated).ToList();
        return View(model);
    }