星空网 > 软件开发 > ASP.net

“entities.LastOrDefault()”引发了类型“System.NotSupportedException”的异常

问题:

var entities = new ShipuPlanBLO().UserList(userId, beginDate, endDate);DateTime maxDate = entities.FirstOrDefault().PlanDate;DateTime minDate = entities.LastOrDefault().PlanDate; //报错

说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 
异常详细信息: System.NotSupportedException: LINQ to Entities 不识别方法“AdminDB.Models.PlanList LastOrDefault[PlanList](System.Linq.IQueryable`1[AdminDB.Models.PlanList])”,因此该方法无法转换为存储表达式。

 

----------------------------------------------------------------------------------------------------------------------------------------

解决方法:

That's because LINQ to Entities (and databases in general) does not support all the LINQ methods (see here for details: http://msdn.microsoft.com/en-us/library/bb738550.aspx)

What you need here is to order your data in such a way that the "last" record becomes "first" and then you can use FirstOrDefault. Note that databasese usually don't have such concepts as "first" and "last", it's not like the most recently inserted record will be "last" in the table.

问题链接:https://social.msdn.microsoft.com/Forums/vstudio/en-US/2ccc7935-c6f5-4bf2-a4cd-0a6de9e38ed8/firstordefault-and-lastordefault?forum=wpf

 

简单来说就是 LINQ to Entities 不支持所有的LINQ方法,LastOrDefault也是不支持的方法之一

[That's because LINQ to Entities (and databases in general) does not support all the LINQ methods ]




原标题:“entities.LastOrDefault()”引发了类型“System.NotSupportedException”的异常

关键词:ie

ie
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

广告出单:https://www.goluckyvip.com/tag/32041.html
广告创建:https://www.goluckyvip.com/tag/32042.html
广告词:https://www.goluckyvip.com/tag/32043.html
广告法规:https://www.goluckyvip.com/tag/32044.html
广告法禁用词汇:https://www.goluckyvip.com/tag/32045.html
广告管理费:https://www.goluckyvip.com/tag/32046.html
探讨内地人开设香港账户的可行性 :https://www.kjdsnews.com/a/1836442.html
在古巴做游轮 古巴旅游项目:https://www.vstour.cn/a/363194.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流