25

我收到此错误

base {System.SystemException} = {"LINQ to Entities does not recognize the method 'System.DateTime AddSeconds(Double)' method, and this method cannot be translated into a store expression."}

在这段代码上

      var eventToPushCustom = eventCustomRepository.FindAllEventsCustomByUniqueStudentReference(userDevice.UniqueStudentReference)
                                    .Where(x => x.DateTimeStart > currentDateTime && currentDateTime >= x.DateTimeStart.AddSeconds(x.ReminderTime))
                                    .Select(y => new EventPushNotification
                                    {
                                        Id = y.EventId,
                                        EventTitle = y.EventTitle,
                                        DateTimeStart = y.DateTimeStart,
                                        DateTimeEnd = y.DateTimeEnd,
                                        Location = y.Location,
                                        Description = y.Description,
                                        DeviceToken = y.UsersDevice.DeviceTokenNotification
                                    });

我相信问题出在 x.DateTimeStart.AddSeconds(x.ReminderTime)

.AddSeconds 在我的情况下的论点必须是“动态的”......知道如何解决它吗?

4

1 回答 1

46

使用EntityFunctions.AddSeconds方法在服务器端创建日期时间。

 .Where(x => x.DateTimeStart > currentDateTime && 
             currentDateTime >= EntityFunctions.AddSeconds(x.DateTimeStart, x.ReminderTime))
于 2013-01-29T12:49:17.973 回答