title: LINQ merge two grouped query results
body: <p>in my domain I have an object called "Block". A "Block" can have "Pins" and "Attributes" attached to it.</p>
  
  <p>I can create two groups which give me the following results:</p>
  
  <p>Group1 is:</p>
  
  <pre><code>Block:B1
      Pin:P1
      Pin:P2
  Block:B2
      Pin:P3
      Pin:P4
  </code></pre>
  
  <p>Group2 is:</p>
  
  <pre><code>Block:B1
      Attribute:Att1, Value: Value1
      Attribute:Att2, Value: Value2
  Block:B2
      Attribute:Att3, Value: Value3
      Attribute:Att4, Value: Value4
  </code></pre>
  
  <p>now I like to merge this two results to something like this:</p>
  
  <p>Resulting group is:</p>
  
  <pre><code>Block:B1
      Pin:P1
      Pin:P2
      Attribute:Att1, Value: Value1
      Attribute:Att2, Value: Value2
  Block:B2
      Pin:P3
      Pin:P4
      Attribute:Att3, Value: Value3
      Attribute:Att4, Value: Value4
  </code></pre>
  
  <p>Is that possible with LINQ? Or do I need un-grouped results to create a grouped result later?</p>
  
  <p>Thanks</p>
  
  <p>EDIT:
  With Road242 solution I get this result:</p>
  
  <pre><code>Pin: P1
  Pin: P2
  Attribute: Att1
  Attribute: Att2
  Pin: P3
  Pin: P4
  Attribute: Att3
  Attribute: Att4
  </code></pre>
  
  <p>The pins and attributes look pretty good, but I lost the blocks as grouping key :-(</p>
  
  <p>EDIT:
  My queries look like this:</p>
  
  <pre><code>var blockPinsQuery = from blockPinRelation in blockPinRelations
              join block in blocks
                  on blockPinRelation.BlockId equals block.Id
              join pin in pins
                  on blockPinRelation.PinId equals pin.Id
              group pin by block
              into g
              select new
                     {
                         Block = g.Key,
                         Pins = g
                     };
  </code></pre>
  
  <p>and</p>
  
  <pre><code>var blockAttributesQuery = from blockAttributeRelation in blockAttributeRelations
                               join block in blocks
                                   on blockAttributeRelation.BlockId equals block.Id
                               join attribute in stringAttributes
                                   on blockAttributeRelation.AttributeId equals attribute.Id
                                     group attribute by block
                                   into g
                                   select new
                                   {
                                       Block = g.Key,
                                       Attributes = g
                                   };
  </code></pre>
  
  <p>as you can see there is a relation-table in between the relevant entities. But this is not important, I guess.</p>
  
  <p>My output routines look like this:</p>
  
  <pre><code>foreach (var group in blockPinsQuery)
          {
              Console.WriteLine("Block:" + group.Block.Name);
              group.Pins.ToList().ForEach(x =&gt; Console.WriteLine("\t" + "Pin:" + x.Name));
          }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>foreach (var group in blockAttributesQuery)
          {
              Console.WriteLine("Block:" + group.Block.Name);
              group.Attributes.ToList().ForEach(x =&gt; Console.WriteLine("\t" + "Attribute:" + x.Name + ", " + "Value: " + x.Value));
          }
  </code></pre>
  
  <p>and for Road242 query:</p>
  
  <pre><code>foreach (var group in joinedResults)
          {
              group.Pins.ToList().ForEach(p =&gt; Console.WriteLine("Pin: " + p.Name));
              group.Attributes.ToList().ForEach(p =&gt; Console.WriteLine("Attribute: " + p.Name));
          }
  </code></pre>