C# – Subsonic query: issue with the produced query

.net-2.0ado.netcsubsonicsubsonic2.2

I'm having a problem with subsonic query. The deal is, I have a view and I want to query it's data to produce something like the following SQL statement:

select * 
from myView
where (col1 like '%a%' or col2 like '%a%' or col3 like '%a%') 
  and col4 = 1 and col5 = 2

But instead the query that is submited to the DB is something like this:

select * 
from myView
where col1 like '%a%' or col2 like '%a%' or col3 like '%a%' 
  and col4 = 1 and col5 = 2

Is there a way to do something like the fisrt query?

Please note I'm using .net 2.0 and subsonic 2.2

Thank you in advance.

Even do, Subsonic rules!

Best Answer

You need to use the Constraint Expressions: WhereExpression, AndExpression, OrExpression, EndExpression.

Anything following “WhereExpression” (or Or/AndExpression) will be wrapped in parentheses. You can close the expression by using “CloseExpression()”, or it will be closed for you if another is started (as with OrExpression above) or if the query ends.

Also see: Using Nested Where/And/Or.

Related Topic