title: Position of .Take() has no effect on generated SQL
body: <p>I've noticed that the position of <code>.Take()</code> has no effect on the resulting SQL. For example say I have this query:</p>
  
  <pre><code>IQueryable&lt;Item&gt; query = 
      db.Items.Where(i =&gt; i.CategoryID == categoryID &amp;&amp; i.Deleted == false)
              .OrderByDescending(i =&gt; i.ItemID).Skip(0);
  </code></pre>
  
  <p>Then do the following two queries:</p>
  
  <pre><code>IQueryable&lt;ItemViewModel&gt; query1 = 
      query.Take(20).Select(i =&gt; new ItemViewModel { ItemID = i.ItemID });
  IQueryable&lt;ItemViewModel&gt; query2 = 
      query.Select(i =&gt; new ItemViewModel { ItemID = i.ItemID }).Take(20);
  </code></pre>
  
  <p>Entity Framework will generate the following identical SQL for both queries:</p>
  
  <pre><code>SELECT TOP (20) 
    [Project1].[ItemID] AS [ItemID], 
  FROM ( SELECT [Project1].[ItemID] AS [ItemID],
     row_number() OVER (ORDER BY [Project1].[ItemID] DESC) AS [row_number]
      FROM ( SELECT 
          [Filter1].[ItemID] AS [ItemID], 
          FROM   (SELECT [Extent1].[ItemID] AS [ItemID], 
      [Extent1].[CategoryID] AS [CategoryID]
      FROM  [dbo].[Items] AS [Extent1]
              WHERE 0 = [Extent1].[Deleted] ) AS [Filter1]
          WHERE ([Filter1].[CategoryID] = @p__linq__0) AND (@p__linq__0 IS NOT NULL)
      )  AS [Project1]
  )  AS [Project1]
  WHERE [Project1].[row_number] &gt; 0
  ORDER BY [Project1].[ItemID] DESC
  </code></pre>
  
  <p>Why does it do this? Shouldn't it instead generate the following for query1 with the <code>TOP 20</code> on the subquery?</p>
  
  <pre><code>SELECT 
      [Project1].[ItemID] AS [ItemID]
      FROM ( SELECT [Project1].[ItemID] AS [ItemID]
          FROM ( SELECT TOP (20)
              [Extent1].[ItemID] AS [ItemID], 
              row_number() OVER (ORDER BY [Extent1].[ItemID] DESC) AS [row_number]
              FROM [dbo].[Items] AS [Extent1]
              WHERE ([Extent1].[CategoryID] = @p__linq__0) AND (@p__linq__0 IS NOT NULL)  
              AND (0 = [Extent1].[Deleted]) AND [Extent1].[row_number] &gt; 0
              ORDER BY [Extent1].[ItemID] DESC
          )  AS [Project1]
      )  AS [Project1]
  </code></pre>
  
  <p>I noticed that moving <code>TOP 20</code> inside will increase the time from 7 seconds to an immediate response in my actual query since it doesn't do the projection before <code>TOP 20</code>. </p>
  
  <p>Edit: Unfortunately I can't seem to find a way to force entity framework to do this since <code>query.Take(20).Select(i =&gt; new { ... }).ToString() == query.Select(i =&gt; new { .. }).Take(20).ToString()</code>. Maybe this is a bug in EF?</p>