title: GroupBy with elementSelector and resultSelector
body: <p>The <code>Enumerable.GroupBy</code> and <code>Queryable.GroupBy</code> extensions have 8 overloads. Two of them (for <code>Enumerable.GroupBy</code>) are:</p>
  
  <pre><code>// (a)
  IEnumerable&lt;TResult&gt; GroupBy&lt;TSource, TKey, TResult&gt;(
      this IEnumerable&lt;TSource&gt; source,
      Func&lt;TSource, TKey&gt; keySelector,
      Func&lt;TKey, IEnumerable&lt;TSource&gt;, TResult&gt; resultSelector);
  
  // (b)
  IEnumerable&lt;TResult&gt; GroupBy&lt;TSource, TKey, TElement, TResult&gt;(
      this IEnumerable&lt;TSource&gt; source,
      Func&lt;TSource, TKey&gt; keySelector,
      Func&lt;TSource, TElement&gt; elementSelector,
      Func&lt;TKey, IEnumerable&lt;TElement&gt;, TResult&gt; resultSelector);
  </code></pre>
  
  <p>(for <code>Queryable.GroupBy</code> the same, just with <code>Expression&lt;Func&lt;...</code> instead of <code>Func&lt;...</code>)</p>
  
  <p><code>(b)</code> has an additional <code>elementSelector</code> as parameter.</p>
  
  <p>On MSDN is <a href="http://msdn.microsoft.com/en-us/library/bb549393.aspx" rel="noreferrer">an example for overload (a)</a> and <a href="http://msdn.microsoft.com/en-us/library/bb534493.aspx" rel="noreferrer">an example for overload (b)</a>. They both work with the same example source collection:</p>
  
  <pre><code>List&lt;Pet&gt; petsList = new List&lt;Pet&gt;
  {
      new Pet { Name="Barley", Age=8.3 },
      new Pet { Name="Boots", Age=4.9 },
      new Pet { Name="Whiskers", Age=1.5 },
      new Pet { Name="Daisy", Age=4.3 }
  };
  </code></pre>
  
  <p>Example (a) uses this query:</p>
  
  <pre><code>var query = petsList.GroupBy(
      pet =&gt; Math.Floor(pet.Age), // keySelector
      (age, pets) =&gt; new          // resultSelector
      {
          Key = age,
          Count = pets.Count(),
          Min = pets.Min(pet =&gt; pet.Age),
          Max = pets.Max(pet =&gt; pet.Age)
      });
  </code></pre>
  
  <p>And example (b) uses this query:</p>
  
  <pre><code>var query = petsList.GroupBy(
      pet =&gt; Math.Floor(pet.Age), // keySelector
      pet =&gt; pet.Age,             // elementSelector
      (baseAge, ages) =&gt; new      // resultSelector
      {
          Key = baseAge,
          Count = ages.Count(),
          Min = ages.Min(),
          Max = ages.Max()
      });
  </code></pre>
  
  <p>The result of both queries is exactly the same.</p>
  
  <p>Question 1: Is there any kind of query that I cannot express by using the <code>resultSelector</code> alone and where I really would need the <code>elementSelector</code>? Or are the capabilities of the two overloads always equivalent and it is just a matter of taste to use one or the other way?</p>
  
  <p>Question 2: Is there a counterpart for the two different overloads when using LINQ query syntax?</p>
  
  <p>(As a side question: When using <code>Queryable.GroupBy</code> with Entity Framework, will both overloads be translated into the exact same SQL?)</p>