Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I receive this error on

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."}

on this code

      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
                                    });

I believe the problem is in x.DateTimeStart.AddSeconds(x.ReminderTime)

The argument of .AddSeconds in my case must be "dynamic" ... Any idea how to solve it?

like image 403
GibboK Avatar asked Jan 29 '13 12:01

GibboK


1 Answers

Use EntityFunctions.AddSeconds method to create date time on server side.

 .Where(x => x.DateTimeStart > currentDateTime && 
             currentDateTime >= EntityFunctions.AddSeconds(x.DateTimeStart, x.ReminderTime))
like image 110
Sergey Berezovskiy Avatar answered Nov 17 '22 07:11

Sergey Berezovskiy