Skip to content

Commit 7ad72a1

Browse files
committed
Add parenthesis on filter
When combining several filters by calling Filter() multiple times, they will be joined by "and" which is "fine". The issues comes when there's an or in one of the filters, which will produce unexpected results. e.g. Filter(x => x.Foo == "some string") Filter(x => x.Bar == 1 || x.Bar == 2 ) Should be: "(Foo eq 'some string') and (Bar eq 1 or Bar eq 2)" But will be: "Foo eq 'some string' and Bar eq 1 or Bar eq 2"
1 parent 0168279 commit 7ad72a1

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/OData.QueryBuilder/Expressions/Visitors/ODataOptionFilterExpressionVisitor.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,11 @@ protected override string VisitLambdaExpression(LambdaExpression lambdaExpressio
254254

255255
private bool HasParenthesis(ExpressionType expressionType)
256256
{
257-
var hasParenthesis = _expressionType.HasValue && expressionType switch
257+
258+
var hasParenthesis = expressionType switch
258259
{
259-
ExpressionType.And => true,
260-
ExpressionType.AndAlso => true,
260+
ExpressionType.And => true && _expressionType.HasValue,
261+
ExpressionType.AndAlso => true && _expressionType.HasValue,
261262
ExpressionType.Or => true,
262263
ExpressionType.OrElse => true,
263264
_ => false,

0 commit comments

Comments
 (0)