LINQ to Entities不识别ElementAt(i)的方法; [英] LINQ to Entities does not recognize the method ElementAt(i);

查看:398
本文介绍了LINQ to Entities不识别ElementAt(i)的方法;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用方法 elementat(Int32)来获取查询结果的特定元素。

I'm using the method elementat(Int32) to get a specific element of a query's result.

var mds = db.TDP_MissioniDestinazioni.Where(p => p.MissioneID == missioneRow.MissioneID);  

destinazioneRow = mds.ElementAt(i);




LINQ to Entities不识别方法
'TimeEntModel .TDP_MissioniDestinazioni
ElementAt [TDP_MissioniDestinazioni]

(System.Linq.IQueryable`1 [TimeEntModel.TDP_MissioniDestinazioni],
Int32)'方法,此方法无法转换为商店
表达式。

LINQ to Entities does not recognize the method 'TimeEntModel.TDP_MissioniDestinazioni ElementAt[TDP_MissioniDestinazioni]
(System.Linq.IQueryable`1[TimeEntModel.TDP_MissioniDestinazioni], Int32)' method, and this method cannot be translated into a store expression.

为什么我收到此错误,我该如何解决?

Why am I getting this error and how can I fix it?

推荐答案

您是否乐意获取所有较早的结果?如果是这样,可以调用 ToList()来缓存它们,或者 AsEnumerable()在每次调用时提取它们, AsEnumerable 只是强制编译器调用 Enumerable.ElementAt 而不是可查询的方式.ElementAt

Are you happy to fetch all the "earlier" results? If so, either call ToList() to cache them, or AsEnumerable() to fetch them on each call, with the AsEnumerable just being a way to force the compiler to call Enumerable.ElementAt instead of Queryable.ElementAt.

尽管如此,可能会有更好的方式(例如使用Take或Skip),可以提供更多的信息?

There may be a better way (e.g. using Take or Skip) though - could you give more information about the bigger picture?

这篇关于LINQ to Entities不识别ElementAt(i)的方法;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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