title: Why am I getting an InvalidOperationException with this Linq to Sql method?
body: <p>When Executing the following linq to sql statement:</p>
  
  <pre><code>    var stuff = from l in _db.SqlLinks
                  select new
                             {
                                 Link = l,
                                 Rating = (from v in l.SqlLinkVotes
                                           where v.Tag == tagId
                                                 &amp;&amp; v.VoteDate &gt;= since
                                           select v.Vote).Sum(),
                                 NumberOfVotes = (from v in l.SqlLinkVotes
                                                  where v.Tag == tagId
                                                        &amp;&amp; v.VoteDate &gt;= since
                                                  select v.Vote).Count(),
                                 NumberOfComments = (from v in l.SqlLinkVotes
                                                     where v.Tag == tagId
                                                           &amp;&amp; v.VoteDate &gt;= since
                                                           &amp;&amp; v.Comment != ""
                                                     select v.Vote).Count()
                             };
  </code></pre>
  
  <p>I get a System.InvalidOperationException (null value cannot be assigned to Int32).</p>
  
  <p>Through debugging I've seen that this comes from the Rating property of the dynamic object. </p>
  
  <p>When there are no SqlLinkVotes for a particular link the Sum() results in a null value, but Rating is an int, and linq to sql thinks the Sum() will result in an int, not a nullable int.</p>
  
  <p>I could easily write a stored procedure to get around this, but I thought it was a good way for me to understand linq to sql more.</p>
  
  <p>Please help!</p>