title: Lambda query translate .count as select rows (EF6 code first)
body: <p>I have 2 simple tables.</p>
  
  <p>Post is the master and has n votes. I want to return posts with their vote count. 
  This is my code:</p>
  
  <pre><code>db.posts.Select(p=&gt;
  new PostlDto{Title= p.Title, VoteCount= p.Votes.Count})
  </code></pre>
  
  <p>It is ok that I have 1 call to get posts and several calls to get counts. 
  <strong>but the problem is that each time it selects the rows instead of counting them</strong> which is a time consuming action.
  This is what sql profiler shows me</p>
  
  <pre><code>exec sp_executesql N'SELECT 
      [Extent1].[Id] AS [Id], 
      [Extent1].[PostId] AS [PostId], 
      FROM [dbo].[Votes] AS [Extent1]
      WHERE [Extent1].[PostId] = @EntityKeyValue1',N'@EntityKeyValue1 int',@EntityKeyValue1=6
  </code></pre>
  
  <p>I also tried to take the count 1 call by including the votes table in base query, but it also take too long because it also returns rows instead of count of them. :|</p>
  
  <pre><code> db.posts
  .Include(p=&gt;p.Votes)
  .Select(p=&gt;
   new PostlDto{Title= p.Title, VoteCount= p.Votes.Count})
  </code></pre>
  
  <p>This is the query it translates to </p>
  
  <pre><code>SELECT 
      [Project1].[Id] AS [Id], 
      [Project1].[Title] AS [Title], 
      [Project1].[C1] AS [C1], 
      [Project1].[Id1] AS [Id1], 
      [Project1].[Pid] AS [Pid], 
      [Project1].[PostId] AS [PostId], 
      FROM ( SELECT 
          [Extent1].[Id] AS [Id], 
          [Extent1].[Title] AS [Title], 
          [Extent2].[Id] AS [Id1], 
          [Extent2].[PostId] AS [PostId], 
          CASE WHEN ([Extent2].[Id] IS NULL) THEN CAST(NULL AS int) ELSE 1 END AS [C1]
          FROM  [dbo].[Posts] AS [Extent1]
          LEFT OUTER JOIN [dbo].[Votes] AS [Extent2] ON [Extent1].[Id] = [Extent2].[PostId]
      )  AS [Project1]
      ORDER BY [Project1].[Id] ASC, [Project1].[C1] ASC
  </code></pre>
  
  <p>How can I change it to run a simple count instead?! :|</p>
  
  <p>These queries take multiple seconds to run!</p>