title: Linq query with Average
body: <p>I have 3 tables:</p>
  
  <pre><code>tblCompany : Id, Name, Location 
  tblRating  : Id, CompanyId, Rate 
  tblImages  : Id, CompanyId, ImagePath
  </code></pre>
  
  <p>I have a class </p>
  
  <pre><code>public class Company
  {
      public string Id { get; set; }
      public string CompanyName { get; set; }
      public string Location { get; set; }
      public string AverageRate { get; set; }
      public List&lt;string&gt; ImagePath { get; set; }
  }
  </code></pre>
  
  <p>I want a LINQ query to produce a result to match the <code>Company</code> class.</p>
  
  <p>I wrote this query but it does not work</p>
  
  <pre><code>        List&lt;Company&gt;  result = null;
  
          using (DataContext dc = new DataContext())
          {
              result = (from a in dc.GetTable&lt;tblCompany&gt;()
                        join b in dc.GetTable&lt;tblRating&gt;()
                        on a.Id equals b.CompanyId
                        join c in dc.GetTable&lt;tblImages&gt;()
                        on a.Id equals c.CompanyId
  
                        select new SearchResult
                        {
                            CompanyName = a.Company,
                            Location = a.Location,
                            AverageRate = b.Rate.Average(),
                            ImagePath = c.ImagePath.ToList()
  
                        }).ToList&lt;Company&gt;();
          }
  </code></pre>