title: LINQ query returns error "The expected type was 'System.Int32' but the actual value was null."
body: <p>So this is the query:</p>
  
  <pre><code>from c in Contents
  join cs in DepartmentSharings 
  on c.ContentId equals cs.ContentId
  select c.PrivateCategoryId.Value
  </code></pre>
  
  <p>When I run this I get:</p>
  
  <blockquote>
    <p>A database operation failed while processing the request.
    InvalidOperationException: An exception occurred while reading a
    database value for property 'DepartmentSharing.ContentId'. The
    expected type was 'System.Int32' but the actual value was null.</p>
  </blockquote>
  
  <p>Now I checked the <code>DepartmentSharings.ContentId</code> field in the database, its <code>fk, int, not null</code>. In the class it's <code>public int ContentId { get; set; }</code>. <code>DepartmentSharing.ContentId</code> cannot be <code>null</code>. Also, in LinqPad I can see it returns 58 rows before failing.
   Why am I getting this error?</p>