title: Why do I get a "The result of a query cannot be enumerated more than once" when I get the Count() before enumerating the result?
body: <p>This my code. Simplified for readability</p>
  
  <pre><code>var query = from p in people select p;
  
  // here is the point that probably causes the issue
  ObjectResult&lt;int&gt; idsThatMatch = getIdsThatMatchFullTextSearch("andre");
  query = from p in query where idsThatMatch.Contains(p.id) select p;
  
  var count = query.Count();
  query = query.OrderBy(p =&gt; p.id);
  var pessoas = query.Skip(90).Take(30).ToList();
  </code></pre>
  
  <p>I need to read the count before skip/take to get the total amount of records before paging. The count works fine. But at the last line of my excerpt it triggers the exception</p>
  
  <blockquote>
    <p>The result of a query cannot be enumerated more than once</p>
  </blockquote>
  
  <p>Why? The count isn't supposed to enumerate anything by the way. And how can I solve that? Thank you</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>People thought I was using stored procedures but I'm not. Actually I'm using a "select in". The code is bellow the comment. </p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>I just tested the above code without the "select in" part and it works fine</p>
  
  <p><strong>EDIT 3</strong></p>
  
  <p>Using this line works:</p>
  
  <pre><code>ObjectResult&lt;int&gt; idsThatMatch = (getIdsThatMatchFullTextSearch("andre");
  query = from p in query where idsThatMatch.Contains(p.id) select p).ToArray();
  </code></pre>
  
  <p>Thank you</p>