I have a table of product information with many bit columns. This table can be queried from an interface which has a checkbox for each column. The checkboxes are grouped into several related groups.
For example, three of the columns describe the products suitability for various markets, being Automotive, Aviation and Marine.
If none of these checkboxes are checked, I would like the following SQL to be executed.
SELECT * FROM Products
if Automotive was checked the following SQL should be executed
SELECT * FROM Products WHERE Automotive = 1
and if more than one is checked I would like the options to be OR'd together
SELECT * FROM Products WHERE
Automotive = 1
OR
Aviation = 1
In good old C# & SQL I could achieve this logic by conditionally concating the SQL together but I'm having trouble producing the same logic with Linq.
My problem is how do I conditionally add the WHERE clause and the elements of it to my query.
I'd prefer to only have a single point where the query is executed so, if possible, I would like to avoid using C# if's to branch into different queries.