【问题标题】:Compare Date field with the Today's in the linq query将日期字段与 linq 查询中的今天进行比较
【发布时间】:2021-10-29 04:28:45
【问题描述】:

我正在使用 EF 并在 Linq 查询 where 子句中尝试将今天的日期与 Azure SQL Server 数据库表中的日期列进行比较。

表格中的列:

模型类中的字段:

public DateTime OrderDate { get; set; }

我尝试了多种不同的方法来检查 Linq 查询中的 OrderDate = today's date 是否有任何返回结果,即使订单上有今天的日期

下面是我的 linq 查询

var orderData = from mo in _context.MOrders
                from cus in _context.Customers
                where mo.CustomerId == cus.CustomerId
                      && mo.OrderDate == DateTime.Today.Date

我也试过mo.OrderDate.Date == DateTime.Today.Date,但没有返回记录

【问题讨论】:

    标签: c# entity-framework linq entity-framework-core asp.net-core-mvc


    【解决方案1】:

    这是我做的不好mo.OrderDate.Date == DateTime.Today.Date 工作。但问题是我在 2021 年 10 月 29 日上午 12 点查询数据并查找查询以返回日期为 2021 年 10 月 28 日的订单,认为今天是(2021 年 10 月 28 日)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-10
      • 1970-01-01
      • 2015-11-24
      • 2014-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多