-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Fix Issue 13919: Translation error using negative #21389
Conversation
@@ -737,8 +737,9 @@ protected override Expression VisitSqlUnary(SqlUnaryExpression sqlUnaryExpressio | |||
|
|||
case ExpressionType.Negate: | |||
{ | |||
_relationalCommandBuilder.Append("-"); | |||
_relationalCommandBuilder.Append("-("); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use RequiresBrackets helper, so that we don't add parentheses for simple expressions like negate(column) or negate(constant)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also add tests for negate on a column, as well as negate on like expression
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the valuable feedback; I have implemented your suggestions in my latest commits. Please let me know if there's anything I missed or can improve upon.
@jonlouie - You will need to sign Contributor License Agreement before we can process this PR. |
@smitpatel Thank you for the reminder and your patience- had to secure approval before signing the CLA. |
@jonlouie I have merged the PR. Thank you for the contribution! |
@maumar Amazing! Appreciate the fast turnaround and community inclusion :) |
This pull request resolves Issue #13919: Translation error using negative.
Summary of Issue
If a LINQ query references an entity property and uses a negated expression, negation only applies to the first term in the expression.
Example:
db.Entities.Where(e => e.Num1 == -(e.Num2 + 100))
Expected translation:
SELECT ... FROM Entities e WHERE e.Num1 = -(e.Num2 + 100)
Actual translation:
SELECT ... FROM Entities e WHERE e.Num1 = -e.Num2 + 100
Summary of Changes
ExpressionType.Negate
Concerns