title: How to flatten a GroupBy and select in linq
body: <p>I have a query that's returning some grouped data, and I'm drawing a blank on how to "flatten" it so that top level information is available at each group.</p>
  
  <pre><code>Account A
      - Group A
      - Group B
      - Group C
      - etc
  
  Account B
      - Group B
      - Group C
  </code></pre>
  
  <p>What I want to do is "flatten" this to:</p>
  
  <pre><code>Account A | Group A | Sum(Group)
  Account A | Group B | Sum(Group)
  Account A | Group C | Sum(Group)
  Account B | Group B | Sum(Group)
  Account B | Group C | Sum(Group)
  </code></pre>
  
  <p>Here's what I have so far, but I'm not totally sure where to go</p>
  
  <pre><code>var transactions = Accounts.Where(clause)
      .Select(x =&gt; new
      {
          Account = x,
          TransGroupedByBucket = x.TransactionLogs.GroupBy(tl =&gt; tl.TransactionType.BucketTypeID)
      })
  
      //pseudocode
      //Select  new {
      //   Account,
      //   One_TransactionLog_Group
      //}
  
      //will run for each group:
      .Select(x =&gt; new
      {
          AccountInfo = x.Account.ID
          Sum = One_TransactionLog_Group.Sum(tl =&gt; tl.Amount)
      })
      ;
  </code></pre>
  
  <p>I think I'm just having a brain fart, can someone point me in the right direction? One idea I had was to flip it to start at the <code>TransactionLog</code> level and traverse to the <code>Account</code>, but there might be 0 <code>TransactionLog</code>s for an <code>Account</code>, so that might not work properly.</p>