title: LINQ grouping by child properties
body: <p>I'm using the GroupByMany extension method illustrated here:</p>
  
  <p><a href="http://blogs.msdn.com/b/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx" rel="nofollow">http://blogs.msdn.com/b/mitsu/archive/2007/12/22/playing-with-linq-grouping-groupbymany.aspx</a></p>
  
  <p>This is working great, except I'm trying to group based on a list of entity properties.</p>
  
  <p>An example of this would be a Car class that has a set of properties:</p>
  
  <pre><code>    public class Car
      {
          private string Model {get; set;}
          private int Year {get; set;}
          private List&lt;CarProperty&gt; Properties { get; set; }
      }
  
      public class CarProperty
      {
          private string Name { get; set; }
          private string Value { get; set; }
      }
  </code></pre>
  
  <p>If I have a list of Car objects and the respective properties. The main issue is that the class can contain multiple properties with the same name:</p>
  
  <pre><code>Car1 : {"Colour", "Red"}, {"Colour", "Blue"}
  Car2 : {"Colour", "Blue"}
  Car3 : {"Colour", "Black"}, {"Colour", "Red"}
  Car4 : {"Colour", "Yellow"}
  </code></pre>
  
  <p>I can create group selectors to group by 'Year' or 'Model' very easily:</p>
  
  <pre><code>c =&gt; c.Model;
  c =&gt; c.Year;
  </code></pre>
  
  <p>The problem is I'm trying to create a group selector for one of the properties.
  I have tried this (to group by car colour):</p>
  
  <pre><code>c =&gt; c.Properties.Where(p =&gt; p.Name == "Colour").Select(p =&gt; p.Value));
  </code></pre>
  
  <p>But it's create a composite grouping key. I somehow need to flatten the list of possible grouping values to give:</p>
  
  <pre><code>Red: Car1, Car3
  Blue: Car1, Car2
  Black: Car3
  Yellow: Car4
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>If the GroupByMany isn't the way to go, I'd appreciate any suggestions to take a list of groupings like {"Year", "Model", "Colour"} which will multi-level group the cars in the same order as the list of groups.</p>
  
  <pre><code>Year
    --&gt; Model
      --&gt; Colour
  </code></pre>