1

在我的 [项目中,我使用的是 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.

如何解决?

4

1 回答 1

5

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

int now = DateTime.Now.DayOfYear.AddDays(-90);
var items = (from e in db.Table1
                where e.Created > now
                select e).ToList(); 
于 2013-05-07T12:34:18.087 回答