I'm using the standard visitor pattern to iterate through a LINQ expression tree in order to generate dynamic SQL WHERE clauses.
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.
Given this hypothetical lambda expression:
h => h.Enabled || h.Enabled == false
It would be easy to mistakenly generate this code:
WHERE Enabled OR Enabled = 0
or this code:
WHERE (Enabled = 1) OR (Enabled = 1) = 0
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?
EDIT: The example above is of course redundant - I am only using it to illustrate a point.
Examples that could create this scenario:
h => h.Enabled
h => h.Enabled == enabled
h => h.Enabled == true
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.