Search code examples
c#odata

How does System.Web.OData.Query.ODataQueryOptions.Filter handle parenthesis


I am parsing a ODataQueryOptions object into an SQL query and while parsing the FilterQueryOption member I noticed the FilterClause.Expression node tree does not contain any explicit information about parenthesis. Instead the order in which the "and" and "or" nodes appear changes when parenthesis changes.

What are the rules the ODataQueryOptions uses when creating the node tree representing the filter expression that would let it infer where the parenthesis are?


Solution

  • I figured it out, so for any one wondering here is how it works:

    For any OR node, encapsulate the entire left term and the entire right term in parenthesis.

    IE, for ab|c(d|e), the tree is structured so that an OR node will connect d and e, so that term should be "(d or e)", and an OR node connects ab and c(d|e) so the term should be "(a and b or c and (d or e))".