title: How to extract child groups from parent and re group using Linq
body: <p>I have strange requirement. I am grouping records on the basis of certain criteria ( e.g Gln and other fields...) For each group I have further list of objects. I realized that few object from those list must be separated and need to replicate another group with the same Gln. Because, those objects should not be placed there. They must formulate another group with the same key ( i.e Gln ). </p>
  
  <p>Please have a look on following code.</p>
  
  <pre><code>var claimsQuery = (from consignment in Consignments
                  let consigneeAddress = consignment.ConsignmentAddresses.FirstOrDefault(pr =&gt; pr.AddressTypeId == 2)
                  where (consignment.ClientId == 26 &amp;&amp; consignment.FixDate != null )
                  group consignment by new 
                  {                                               
                      consigneeAddress.GLN,
                      consignment.ForwarderId,
                      consigneeAddress.Country.ISO,
                      consignment.FixDate,
                      ProductName = Products.FirstOrDefault(pr =&gt; pr.ProductId == consignment.ProductId).Name,
                      ProductId = consignment.ProductId
                  }
                  into g
                  select new DepoOverviewData
                  {
  
                      ForwarderId = g.Key.ForwarderId,
                      FixDate = g.Key.FixDate.GetValueOrDefault(),
                      Gln = g.Key.GLN,
                      ProductName = g.Key.ProductName,                                                
  
                      ConsignmentsOverviewData  = 
                              (from singleConsignment in Consignments.Where(pr =&gt; ( pr.FixDate == g.Key.FixDate)  &amp;&amp; ( pr.ProductId ==  g.Key.ProductId))             
                               join x in ConsignmentAddresses on singleConsignment.ConsignmentId equals x.ConsignmentId
                               where x.GLN == g.Key.GLN &amp;&amp; x.AddressTypeId == 2
  
                               select new ConsignmentClaimsOverviewData()
                               {                                          
                                      ConsignmentId = singleConsignment.ConsignmentId,
                                      Weight = singleConsignment.Weight,
                                      ChargeableWeight = singleConsignment.ChargeableWeight,
                                      TotalCost = singleConsignment.NetTotalCost,
                                      ProductId = singleConsignment.ProductId,
                                      ProductName = Products.FirstOrDefault(pr =&gt; pr.ProductId == singleConsignment.ProductId).Name,
                                      FixDate = singleConsignment.FixDate,
                                      ExpressTime = singleConsignment.ExpressTime, 
                                      ClientOrderNumber = singleConsignment.ClientOrderNumber,
                                      DeliveryDate = singleConsignment.DeliveryDate,   
                                      InTime = false, // this will be reset later. ( i.e True, false or null after iterating again over each group ).
  
                               }).ToList()
                  }).ToList();
  </code></pre>
  
  <p>I also attached one image to demonstrate things.<a href="https://i.stack.imgur.com/mfYJw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mfYJw.png" alt="enter image description here"></a></p>