【发布时间】:2011-09-28 18:39:25
【问题描述】:
这是我的代码。为便于阅读而简化
var query = from p in people select p;
// here is the point that probably causes the issue
ObjectResult<int> idsThatMatch = getIdsThatMatchFullTextSearch("andre");
query = from p in query where idsThatMatch.Contains(p.id) select p;
var count = query.Count();
query = query.OrderBy(p => p.id);
var pessoas = query.Skip(90).Take(30).ToList();
我需要在 skip/take 之前读取计数以获取分页前的记录总数。计数工作正常。但在我摘录的最后一行,它触发了异常
一个查询的结果不能多次枚举
为什么?顺便说一句,计数不应该枚举任何东西。我该如何解决呢?谢谢
编辑
人们以为我在使用存储过程,但我没有。实际上我正在使用“选择”。代码在评论下方。
编辑 2
我刚刚测试了上面没有“select in”部分的代码,它工作正常
编辑 3
使用这条线有效:
ObjectResult<int> idsThatMatch = (getIdsThatMatchFullTextSearch("andre");
query = from p in query where idsThatMatch.Contains(p.id) select p).ToArray();
谢谢
【问题讨论】:
标签: .net entity-framework