title: Linq extension method
body: <p>I frequently need to limit SELECTs by fields like <code>publishStart</code>, <code>publishEnd</code>, <code>active</code></p>
  
  <p>I have these fields in several different tables. So only rows should be selected, that are </p>
  
  <pre><code>a: active == true;
  b: publishStart &lt; now;
  c: publishEnd &gt; now;
  </code></pre>
  
  <p>So, for example: </p>
  
  <pre><code>db.myTable.SingleOrDefault(a =&gt; (a.ID == _theID 
            //now the active and start-end part:            
                        &amp;&amp; ((a.publishEnd &gt; DateTime.Now) || (a.publishEnd == null))
                        &amp;&amp; ((a.publishStart &lt;= DateTime.Now) || (a.publishStart == null))
                        &amp;&amp; a.active == true));
  </code></pre>
  
  <p>This is a bit lengthy, so I wonder if it is possible to create a (extension?)-method like:</p>
  
  <pre><code>db.myTable.SingleOrDefault(a =&gt; (a.ID == _theID).isActive()
  </code></pre>
  
  <p>where the <code>isActive()</code> provides the 3 lines of the above snippet.</p>
  
  <p>How could I do this?
  Is there a better way to clean up code?</p>