title: How to delegate parts of a where clause to a different area
body: <p>The particular situation I am currently trying to get around involves a bool? referencing a nullable bit field in the database. But the logic should apply to many different cases.</p>
  
  <p>I am using Entity Framework and have an object with a bool? property. I am starting to write a lot of Linq around this particular property, but because Sql doesnt retrieve null values when bool? != true is written, I am finding I am writing queries that look like:</p>
  
  <pre><code>var Result = from f in FooList
               where f.NullableBool == false || f.NullableBool == null
               where f.Bar.Contains(SearchTerm)
               select f;
  </code></pre>
  
  <p>This isn't a massive problem, but I would really like to be able to remove the "x.NullableBool == false || x.NullableBool == false" to a different place and instead call something like:</p>
  
  <pre><code>var Result = from f in FooList
               where f.IsNot &amp;&amp; f.Bar.Contains(SearchTerm)
               select f;
  </code></pre>
  
  <p>I have tried adding properties and methods of types like 'Expression &lt; Func &lt; Foo, bool > >', 'Func &lt; Foo, bool >' and 'bool' to the Foo class but Linq doesn't seem to like them.</p>
  
  <p>Any pointers greatly appreciated.</p>
  
  <p>Thanks</p>