title: LINQ to SQL find average of field?
body: <p>I have a ViewModel called EntityRating, one of whose properties is AverageRating.</p>
  
  <p>When I instantiate a new object of my ViewModel (called EntityRating) type, how do I set the EntityRating.AverageRating based on the Rating field (in SQL Server) of the item in question?</p>
  
  <p>I want to do something like this (which obviously doesn't work):</p>
  
  <pre><code>var er = new EntityRating()
          {
              AverageRating = _db.All&lt;Ratings&gt;(X =&gt; X.RatingID = rating.RatingID).Average(RatingField);
          };
  </code></pre>
  
  <p>Can I average the properties of an object in the database and assign it to the property of an object in my code?</p>
  
  <p>(Pretty new, so let me know if any terminology is off, or if you need more info)</p>
  
  <p>Thanks.</p>