Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
722 views
in Technique[技术] by (71.8m points)

entity framework - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

 .Where(x => x.DateTimeStart > currentDateTime && 
             currentDateTime >= EntityFunctions.AddSeconds(x.DateTimeStart, x.ReminderTime))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...