gpt4 book ai didi

MySQL Connector - LINQ to Entities 无法识别该方法

转载 作者:行者123 更新时间:2023-11-29 04:23:42 25 4
gpt4 key购买 nike

在我的[项目中,我使用的是 MySQL 连接器和 Entity Framework 。我对以下代码有疑问:

   int now = DateTime.Now.DayOfYear;

var items = (from e in db.Table1
let date = e.Created.AddDays(90)
where date.DayOfYear > now
select e).ToList();

但我收到错误信息:

LINQ to Entities does not recognize the method 'System.DateTime AddDays(Double)'
method, and this method cannot be translated into a store expression.

如何解决?

最佳答案

您不能在 linq 查询中使用这些类型的函数,您应该从现在减去 90 天,然后在查询中进行比较

int now = DateTime.Now.DayOfYear.AddDays(-90);
var items = (from e in db.Table1
where e.Created > now
select e).ToList();

关于MySQL Connector - LINQ to Entities 无法识别该方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16419106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com