title: Efficient way to call .Sum() on multiple properties
body: <p>I have a function that uses Linq to get data from the database and then I call that function in another function to sum all the individual properties using .Sum on each individual property. I was wondering if there is an efficient way to sum all the properties at once rather than calling .Sum() on each individual property. I think the way I am doing as of right now, is very slow (although untested). </p>
  
  <pre><code>public OminitureStats GetAvgOmnitureData(int? fnsId, int dateRange)
      {
          IQueryable&lt;OminitureStats&gt; query = GetOmnitureDataAsQueryable(fnsId, dateRange);
  
          int pageViews = query.Sum(q =&gt; q.PageViews);
          int monthlyUniqueVisitors = query.Sum(q =&gt; q.MonthlyUniqueVisitors);
          int visits = query.Sum(q =&gt; q.Visits);
          double pagesPerVisit = (double)query.Sum(q =&gt; q.PagesPerVisit);
          double bounceRate = (double)query.Sum(q =&gt; q.BounceRate);
  
          return new OminitureStats(pageViews, monthlyUniqueVisitors, visits, bounceRate, pagesPerVisit);
      }
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <pre><code>private IQueryable&lt;OminitureStats&gt; GetOmnitureDataAsQueryable(int? fnsId, int dateRange)
      {
          var yesterday = DateTime.Today.AddDays(-1);
          var nDays = yesterday.AddDays(-dateRange);
  
          if (fnsId.HasValue)
          {
              IQueryable&lt;OminitureStats&gt; query = from o in lhDB.omniture_stats
                                                 where o.fns_id == fnsId
                                                       &amp;&amp; o.date &lt;= yesterday
                                                       &amp;&amp; o.date &gt; nDays
                                                 select new OminitureStats ( 
                                                     o.page_views.GetValueOrDefault(), 
                                                     o.monthly_unique.GetValueOrDefault(),
                                                     o.visits.GetValueOrDefault(),
                                                     (double)o.bounce_rate.GetValueOrDefault()
                                                 );
              return query;
          }
          return null;
      }
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <pre><code>public class OminitureStats
      {
          public OminitureStats(int PageViews, int MonthlyUniqueVisitors, int Visits, double BounceRate)
          {
              this.PageViews = PageViews;
              this.MonthlyUniqueVisitors = MonthlyUniqueVisitors;
              this.Visits = Visits;
              this.BounceRate = BounceRate;
              this.PagesPerVisit = Math.Round((double)(PageViews / Visits), 1);
          }
  
          public OminitureStats(int PageViews, int MonthlyUniqueVisitors, int Visits, double BounceRate, double PagesPerVisit)
          {
              this.PageViews = PageViews;
              this.MonthlyUniqueVisitors = MonthlyUniqueVisitors;
              this.Visits = Visits;
              this.BounceRate = BounceRate;
              this.PagesPerVisit = PagesPerVisit;
          }
  
          public int PageViews { get; set; }
          public int MonthlyUniqueVisitors { get; set; }
          public int Visits { get; set; }
          public double PagesPerVisit { get; set; }
          public double BounceRate { get; set; }
      }
  </code></pre>