-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expression predicates combined with bitwise OR do not correctly compose with subsequent predicates #3061
Comments
Expression.Or
do not correctly compose with subsequent predicates
Duplicate of dotnet/efcore#30248 |
This is an EF-side issue; using Or rather than OrElse is generally not the right thing, which is why a quicker fix hasn't been prioritized.
Note that Or being bitwise and OrElse being logical is by-design; this is how the APIs were designed (there's history there). |
@roji |
There could be some operator precedence differences between the two databases... Can you post a minimal, runnable console app that works on SQL Server but fails on PG? |
Context:
We're investigating porting our saas-platform from sql-server to postgresql.
We use an
ExpressionBuilder
helper class to programatically combine multiple lambda expressions.This allows us to more easily combine complex filtering criteria into a larger compound expression.
For instance:
Build-up:
The ExpressionBuilder's "Or" incorrectly combines the two expression bodies with
Expression.Or
instead ofExpression.OrElse
.The former is the Bitwise Or-operator and the latter is the logical Or-operator.
So in essence
compoundPredicate
translates tox => x.Brand == brand1 | x.Brand == brand2;
instead ofx => x.Brand == brand1 || x.Brand == brand2;
.The Issue:
The issue arises, not in how the library handles this bitwise OR. This seems to generate a logical OR in the SQL-statement as expected, but rather in how it composes with subsequent
Where()
filters.What happened:
The first
Where
was not correctly surrounded with parentheses when combined with the secondWhere
in SQL:When I fixed the way the expressions get combined (Using logical OR) the problem was fixed:
But I felt I should mention it, as this does not seem like correct behavior.
The text was updated successfully, but these errors were encountered: