title: How to evaluate a standalone boolean expression in a LINQ expression tree
body: <p>I'm using the standard visitor pattern to iterate through a LINQ expression tree in order to generate dynamic SQL WHERE clauses.</p>
  
  <p>My issue is that unlike C#, you can't use a standalone boolean expression in SQL; you have to compare it to either 1 or 0.</p>
  
  <p>Given this hypothetical lambda expression:</p>
  
  <pre><code>h =&gt; h.Enabled || h.Enabled == false
  </code></pre>
  
  <p>It would be easy to mistakenly generate this code:</p>
  
  <pre><code>WHERE Enabled OR Enabled = 0
  </code></pre>
  
  <p>or this code:</p>
  
  <pre><code>WHERE (Enabled = 1) OR (Enabled = 1) = 0
  </code></pre>
  
  <p>Both of course will generate an SQL error. What logic should I apply to get around this without my code starting to look really obtuse as I delve deep into subtrees to figure out what the case may be?</p>
  
  <p><strong>EDIT: The example above is of course redundant - I am only using it to illustrate a point.</strong></p>
  
  <p>Examples that could create this scenario:</p>
  
  <pre><code>h =&gt; h.Enabled
  h =&gt; h.Enabled == enabled
  h =&gt; h.Enabled == true
  </code></pre>
  
  <p>Naturally that last example is poor style, but my code is being designed to work independent of the programmer's skill level, so to not cater for redundant scenarios would be poor form on my part.</p>