title: LINQ GroupBy - Cannot Implicitly convert type
body: <p>I have a basic LINQ Query that looks like the following:</p>
  
  <pre><code>var results = from x in context.MyEntities
                where (x.CustomerName != null)
                select new Customer()
                {
                  CustomerID = x.CustomerID,
                  FirstName = x.FirstName,
                  LastName = x.LastName,
                  Gender = x.Gender,
                  BirthMonth = x.BirthMonth
                };
  
  results = results.GroupBy(x =&gt; x.Gender);
  results = results.GroupBy(x =&gt; x.BirthMonth);
  
  bool onlyShowKnownGenders = GetWhetherToShowOnlySetGenders();
  if (onlyShowKnownGenders) {
    results = results.Where(x =&gt; ((x.Gender == 1) || (x.Gender == 2)));
  }
  </code></pre>
  
  <p>If I comment out the two "GroupBy" lines, my code works fine. However, I now have a need to group the results. When I include the two "GroupBy" lines, I receive an error that says:</p>
  
  <p><em>Cannot implicitly convert type 'System.Linq.IQueryable>' to 'System.Linq.IQueryable'. An explicit conversion exists (are you missing a cast?)</em></p>
  
  <p>My question is, I'm not sure how to do the cast in this case. Can someone please help me out?</p>
  
  <p>Thank you!</p>