title: how to group by parent and apply aggregate function on its childeren in LinQ Lambda
body: <p>I have a SQL table which holds a parent-child relationship in it own schema via a ParentId column. There are some other tables (Sale, etc.) linked to it via the LocationId column. I am after grouping data based on the second level parents (Code: xxxxx.xxxxx) and then apply some aggregate function such as SUM and COUNT to its <strong>children and itself</strong>.</p>
  
  <p>Expectation Result for seeing the total sales for 2 regions(Victoria, South Australia) would be something like:</p>
  
  <pre><code>DisplayName      TotalSale
  Victoria         $25,000
  South Australia  $30,000
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/NrB5U.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NrB5U.jpg" alt="enter image description here"></a></p>