title: linq calculated value with group by
body: <p>Having a little trouble constructing a linq statement (C#, query syntax but I could handle method sytax). It needs to support grouping as well as a exposing a calculated property. I have a handle on each individually but can't get them to seem to work together. Any help would be appreciated.</p>
  
  <p><strong>Data</strong>  </p>
  
  <pre><code>GrpField          Qty      Price
  -------------     ---      -----
  RED                1        10
  RED                2        10
  RED                1        50
  BLUE               2        30
  BLUE               2        50
  </code></pre>
  
  <p>Output needs to be sum of Total Price (Qty * Price) for each group</p>
  
  <p><strong>Desired Result</strong></p>
  
  <pre><code>RED    80
  BLUE  160
  </code></pre>
  
  <p>This gets me the Total Price line</p>
  
  <pre><code>from x in origdata
  let linetotal = x.qty * x.price
  select new { x.grpfield, x.qty, x.price, linetotal } 
  </code></pre>
  
  <p>But I am unable to group by the new anonymous type since you can't run aggregates like sum on anonymous types. If I run the group first, I can't figure out how to work the linetotal into the mix BEFORE the aggregate sum.</p>