title: Skip() and Take() as Enumerable vs as Queryable
body: <p>I recently ran into an error while trying to use skip and take in a LINQ statement.</p>
  
  <p>My statement looked like this.</p>
  
  <pre><code>DbConxtext.MyTable.Get(c =&gt; c.UserID == id)
      .OrderBy(orderProperty).Skip(index).Take(length).ToList();
  </code></pre>
  
  <p>Which gave me this error</p>
  
  <blockquote>
    <p>Incorrect syntax near 'OFFSET'.\r\nInvalid usage of the option NEXT in the FETCH statement</p>
  </blockquote>
  
  <p>I found out this is caused because OFFSET NEXT and FETCH did not work on sql server 2008, But I knew I was using paging in other places in my code and they all worked fine. </p>
  
  <p>The difference between the ones that worked and this one was that <strong>Skip</strong> and <strong>Take</strong> were extensions of Enumerable on the ones that worked and Queryable on the ones that didnt.</p>
  
  <p>So adding <strong>AsEnumerable()</strong> to the query fixed the issue for me. This seemed to generate SQL that uses <strong>SELECT TOP(10)</strong> instead of <strong>OFFSET</strong> and <strong>FETCH</strong>.</p>
  
  <p><strong>EDIT:</strong> <em>After reading over this again I realize that AsEnumerable will not generate different SQL. It will instead execute the query and do the Skip Take in memory.</em></p>
  
  <pre><code>DbConxtext.MyTable.Get(c =&gt; c.UserID == id)
      .OrderBy(orderProperty).AsEnumerable().Skip(index).Take(length).ToList();
  </code></pre>
  
  <p>My question is what is the difference between using Skip and Take as extensions of Enumerable vs Queryable.</p>
  
  <p>And why did EF decide to generate different SQL between the two cases.</p>