Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8372

AND + OR query filters not working as expected

$
0
0

Hey all,

 

I tried to search everywhere however I couldn't find any answers to my scenario hence I am posting here.

 

I have been doing some tests with odata queries that combine different AND + OR filters and they do not work as expected.

 

For example if you have the query:

 

sales-web/sales.svc/Stores?$filter=(Country eq 'UK' or Country eq 'FR')

 

this will work as expected, returning all entities that have values UK or FR for the Country field.

 

However, when combining the OR condition with an AND, the first part will not work, i.e:

 

sales-web/sales.svc/Stores?$filter=Status eq 1 and (Country eq 'UK' or Country eq 'FR')


This will still return all records that have values UK or FR for the Country field, ignoring the condition for the Status field.
(Yes, i tried all combinations of parentheses without success...)


I found that a workaround is to create a complex query, like:


sales-web/sales.svc/Stores?$filter=(Status eq 1 and Country eq 'UK') or (Status eq 1 and Country eq 'FR')


however I need to build this query programmatically at run time and this becomes too complex because there are many other possible combinations.


Any insights?


Thanks!




Viewing all articles
Browse latest Browse all 8372

Trending Articles