title: Handle Nullable bool in linq query
body: <p>I have a situation where I am passing nullable bool to the method and then in linq query if that parameter is null then I need to fetch all the records otherwise do comparison and return relative values.</p>
  
  <p>Here is what I have tried (Simplifing the method to just ask relavent question)</p>
  
  <pre><code>public List&lt;Something&gt; Fetch(bool? allocated = null){
     return (from x in DbContext.Something 
              where x.Active &amp;&amp; (allocated == null || x.Allocated == allocated.Value)
              select x).ToList();
  }
  </code></pre>
  
  <p>I have also checked for <code>allocated.HasValue</code> but same problem is occuring every time.</p>
  
  <p>The exception which I get is: </p>
  
  <blockquote>
    <p>System.InvalidOperationException: 'Nullable object must have a value.'</p>
  </blockquote>