title: Compare nullable types in Linq to Sql
body: <p>I have a Category entity which has a Nullable ParentId field. When the method below is executing and the categoryId is null, the result seems null however there are categories which has null ParentId value.</p>
  
  <p>What is the problem in here, what am I missing?</p>
  
  <pre><code>public IEnumerable&lt;ICategory&gt; GetSubCategories(long? categoryId)
  {
      var subCategories = this.Repository.Categories.Where(c =&gt; c.ParentId == categoryId)
          .ToList().Cast&lt;ICategory&gt;();
  
      return subCategories;
  }
  </code></pre>
  
  <p>By the way, when I change the condition to (c.ParentId == null),  result seems normal.</p>