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

12,434

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

 .Where(x => x.DateTimeStart > currentDateTime && 
             currentDateTime >= EntityFunctions.AddSeconds(x.DateTimeStart, x.ReminderTime))
Share:
12,434

Related videos on Youtube

GibboK
Author by

GibboK

A professional and enthusiastic Senior Front End Developer. Listed as top 2 users by reputation in Czech Republic on Stack Overflow. Latest open source projects Animatelo - Porting to JavaScript Web Animations API of Animate.css (430+ stars on GitHub) Industrial UI - Simple, modular UI Components for Shop Floor Applications Frontend Boilerplate - An opinionated boilerplate which helps you build fast, robust, and adaptable single-page application in React Keyframes Tool - Command line tool which convert CSS Animations to JavaScript objects gibbok.coding📧gmail.com

Updated on June 14, 2022

Comments

  • GibboK
    GibboK about 2 years

    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?

  • Tyler Forsythe
    Tyler Forsythe about 10 years
    Note that EntityFunctions is now obsolete. Use DbFunctions instead.
  • Sergey Berezovskiy
    Sergey Berezovskiy about 10 years
    @TylerForsythe thanks for update! It's a fast-changing world :)
  • Pažout
    Pažout over 9 years
    {"FUNCTION db.AddMinutes does not exist"} :(
  • Sergey Berezovskiy
    Sergey Berezovskiy over 9 years
    @Pažout are you using MySQL database?
  • Shaiju T
    Shaiju T almost 9 years
    @ Tyler Forsythe ,which version of entity framework is needed for using DbFunctions ?