简体   繁体   English

查询结果不能被枚举一次以上

[英]The result of a query cannot be enumerated more than once Exception

I'm trying to retrieve a specific number of data for paging, I have no idea why the Skip Query returns an empty List and it throws the following exception "The result of a query cannot be enumerated more than once" 我正在尝试检索特定数量的数据以进行分页,我不知道为何“跳过查询”返回一个空的列表,并引发以下异常“查询结果不能被多次枚举”

IEnumerable<ImgOrgSet> query = _ImgOrgRepository.GetImgOrgList();
IEnumerable<ImgOrgSet> queryPaginated = query.OrderBy(x => x.Id).Skip((CurrentPage - 1) * PageSize).Take(PageSize);

调试细节

如以上注释和路标重复所示,您需要添加.ToList()以使结果明确可用于进一步处理。

I think it throws the exception because you expanded the 'query' variable before in the 'debug window'. 我认为它引发了异常,因为您之前在“调试窗口”中扩展了“查询”变量。 Try running it again and don't expand the query/debug. 尝试再次运行它,不要扩展查询/调试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM