【问题标题】:MySQL Connector - LINQ to Entities does not recognize the methodMySQL 连接器 - LINQ to Entities 无法识别该方法
【发布时间】:2013-05-01 09:50:48
【问题描述】:

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

   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.

如何解决?

【问题讨论】:

    标签: mysql asp.net-mvc-3 entity-framework linq-to-entities


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-11-06
      相关资源
      最近更新 更多