You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 6 EF Core:如何查询排除今日的波斯历日期数据库记录?

问题

我有一张存储日期值的数据表,其中日期字段为字符串类型,格式示例为"1401/09/23"(波斯历)。我需要获取昨日的记录,当前的查询代码仅能对记录按日期降序排序:

public async Task<List<Reservation>> GetReservations()
{
    return await _context.Reservations.OrderByDescending(r => r.DateReserve).ToListAsync();
}

我尝试了以下查询代码,但执行时出现错误:

return await _context.Reservations.Where(r => DateTime.Parse(r.DateReserve, CultureInfo.InvariantCulture) >= DateTime.Parse(DateConvertor.ToShamsi(), CultureInfo.InvariantCulture)).ToListAsync();

错误提示

LINQ to Entities 无法识别方法“System.DateTime Parse(System.String, System.IFormatProvider)”,因此该方法无法转换为存储表达式。


内容的提问来源于stack exchange,提问作者sunboy_sunboy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 13:35:27