title: Converting SQL statement using SUM() to Linq/Entity Framework
body: <p>I'm trying to figure out how to convert the following SQL statement to Entity Framework using Linq:</p>
  
  <pre><code>SELECT SUM(Column1) AS Correct
       , SUM(Column2) AS Incorrect
       , UserName
  FROM   Stats 
  WHERE (StatType = 0)
  GROUP BY UserName
  ORDER BY UserName 
  </code></pre>
  
  <p>For the purposes of this question, all the column types in the DB are type INT, and there are multiple rows of data per user. I basically want 3 columns in my output, with the total of correct &amp; incorrect selections for each user.</p>
  
  <p>It seems like such a simple SQL statement but whatever I try in something like LinqPad, I always get errors. I must be missing something relatively simple. As soon as I start add a ".Sum" clause I get compilation errors etc.</p>
  
  <pre><code>Stats.Where(s =&gt; s.StatType == 0)
       .GroupBy(s =&gt; s.UserName)
       .Select(x =&gt; new {  Correct = x.Column1
                         , Incorrect = x.Column2
                         , User=x.UserName})
       .ToList()
  </code></pre>