title: Accept method to return null - C# .NET MVC
body: <p>I am building a little application in .NET 4 MVC 2 for the office foosball table. I have this repository with a method summing all the values of one column (decimal) using LINQ to SQL. It looks like this:</p>
  
  <pre><code>public decimal GetPlayerRating(int id)
  {
      var playerRating = (from r in db.Ratings
                          where r.PlayerID == id
                          select r.Points).Sum();
  
      return playerRating;
  }
  </code></pre>
  
  <p>The problem is that sometimes when it's called it returns <code>null</code> because the given player does not have any records in the table. That's fine -- in that case it should just return zero. But I get this error:</p>
  
  <blockquote>
    <p>The null value cannot be assigned to a
    member with type System.Decimal which
    is a non-nullable value type.</p>
    
    <p>Description: An unhandled exception
    occurred during the execution of the
    current web request. Please review the
    stack trace for more information about
    the error and where it originated in
    the code. </p>
    
    <p>Exception Details:
    System.InvalidOperationException: The
    null value cannot be assigned to a
    member with type System.Decimal which
    is a non-nullable value type.</p>
  </blockquote>
  
  <p>How can I tell my method that it is okay to return a null value? Thanks!</p>