title: The cast to value type 'Int32' failed because the materialized value is null
body: <p>I have the following code. I'm getting error: </p>
  
  <blockquote>
    <p>"The cast to value type 'Int32' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type." </p>
  </blockquote>
  
  <p>when CreditHistory table has no records.</p>
  
  <pre><code>var creditsSum = (from u in context.User
                    join ch in context.CreditHistory on u.ID equals ch.UserID                                        
                    where u.ID == userID
                    select ch.Amount).Sum();
  </code></pre>
  
  <p>How can I modify the query to accept null values?</p>