2013-01-29 11 views
15

ricevo questo errore suLINQ alle entità non riconosce il metodo 'System.DateTime AddSeconds (doppia)' metodo, e questo metodo non può essere tradotto in

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

su questo codice

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

Credo che il problema sia in x.DateTimeStart.AddSeconds(x.ReminderTime)

L'argomento di .AddSeconds nel mio caso deve essere "dinamico" ... Qualche idea su come risolverlo?

risposta

30

Utilizzare il metodo EntityFunctions.AddSeconds per creare l'ora della data sul lato server.

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

Si noti che EntityFunctions è ora obsoleto. Usa invece 'DbFunctions'. –

+0

@TylerForsythe grazie per l'aggiornamento! È un mondo in rapida evoluzione :) –

+0

{"FUNCTION db.AddMinutes non esiste"} :( –