title: Linq Select Group By
body: <p>I have the following class structure :</p>
  
  <pre><code>public class PriceLog
  {
     public DateTime LogDateTime {get; set;}
     public int Price {get; set;}
  }
  </code></pre>
  
  <p>For a <strong>List&lt; PriceLog ></strong> I want a Linq query to generate an output which is equivalent to the data represented as below:</p>
  
  <p>LogDateTime | AVG(Price)<br>
  Jan 2012    | 2000<br>
  Feb 2012    | 3000</p>
  
  <p>Simply : I want to compute the average price over each month of the year.<br>
  Note: LogDateTime property should be formatted as <code>LogDateTime.ToString("MMM yyyy")</code></p>
  
  <p>I have tried the following, but not sure whether it will generate the desired result:</p>
  
  <pre><code>var result = from priceLog in PriceLogList
                           group priceLog by priceLog.LogDateTime.ToString("MMM yyyy") into dateGroup
                           select new PriceLog { GoldPrice = (int)dateGroup.Average(p =&gt; p.GoldPrice), SilverPrice = (int)dateGroup.Average(p =&gt; p.SilverPrice)};
  </code></pre>