LINQ to Entities不能识别方法'System.DateTime AddSeconds(Double)'方法,而且这种方法不能被翻译成 [英] LINQ to Entities does not recognize the method 'System.DateTime AddSeconds(Double)' method, and this method cannot be translated into

查看:320
本文介绍了LINQ to Entities不能识别方法'System.DateTime AddSeconds(Double)'方法,而且这种方法不能被翻译成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  base {System.SystemException} = {LINQ to Entities不识别方法 System.DateTime AddSeconds(Double)'方法,并且此方法无法转换为存储表达式。} 

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,
位置= y.Location,
描述= y.Description,
DeviceToken = y.UsersDevice.DeviceTokenNotification
});

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



在我的情况下.AddSeconds的参数必须是动态的...任何想法如何解决?

解决方案

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

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


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?

解决方案

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

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

这篇关于LINQ to Entities不能识别方法'System.DateTime AddSeconds(Double)'方法,而且这种方法不能被翻译成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆