title: Calculate sum of column using group by in Linq
body: <p>I have a list with this structure :</p>
  
  <pre><code>public class Factor
      {
          public DateTime? date { set; get; }
          public string InnovoiceId { set; get; }
          public string explain { set; get; }
          public string tax { set; get; }
          public string transport { set; get; }
          public Int64? bedehkar { set; get; }
          public Int64? bestankar { set; get; }
          public Int64? mande { set; get; }
      }
  
          List&lt;Factor&gt; factors = new List&lt;Factor&gt;();
  </code></pre>
  
  <p>I created a query that groups the records based on <strong>InnovoiceId</strong> .And calculate the sum of <strong>Tax</strong> and sum of <strong>transport</strong> and <strong>bedehkar</strong> and <strong>bestankar</strong> and <strong>mande</strong>.</p>
  
  <p>My query is: </p>
  
  <pre><code>  List&lt;Factor&gt; factorSortList =
             factors.OrderBy(o =&gt; o.date)
                    .ToList()
                    .GroupBy(i =&gt; i.InnovoiceId)
                    .Select(g =&gt; new { tax = g.Sum(i =&gt; Convert.ToInt32(i.tax)), transport = g.Sum(i =&gt; Convert.ToInt32(i.transport)), bedehkar = g.Sum(i =&gt; i.bedehkar), bestankar = g.Sum(i =&gt; i.bestankar), mande = g.Sum(i =&gt; i.mande) });
  </code></pre>
  
  <p>But i got this  error:</p>
  
  <pre><code>   Cannot implicitly convert type 'System.Collections.Generic.IEnumerable&lt;AnonymousType#1&gt;' to 'System.Collections.Generic.List&lt;samtaApplication.BuLayer.Payment.ReportPayment.Factor&gt;'. An explicit conversion exists (are you missing a cast?)
  </code></pre>