title: Linq to Sql Group By Class
body: <p>I would like to pass a groupedList to several functions, however I'm getting strange results when trying to group by using a class rather than an anonymous type. In the following example the anonymous type returns 2 results, as expected, but the concrete class returns 5, as if it wasn't even grouped. </p>
  
  <p>The Question: Is it possible to do Linq to Sql Group By with concrete classes?</p>
  
  <pre><code>public class person
  {
      public string Name;
      public string State;
  }
  
  public class personGroup
  {
      public string State;
      public personGroup(string personState)
      {
          State = personState;
      }
  }
  
  
  void Main()
  {   
      var people = new List&lt;person&gt;();
      people.Add(new person {Name = "Bob", State = "Tx"});
      people.Add(new person {Name = "Bill", State = "Tx"});
      people.Add(new person {Name = "Tracy", State = "Tx"});
      people.Add(new person {Name = "Steve", State = "Md"});
      people.Add(new person {Name = "Kelly", State = "Md"});
  
      var groupedPeople = people.GroupBy (p =&gt; p.State );
      groupedPeople.Count().Dump();//Returns 2
  
      var morePeople = people.GroupBy (p =&gt; new personGroup(p.State) );
      morePeople.Count().Dump();//Returns 5
  }
  </code></pre>