Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed a nasty bug related to flipping binary comparison operations wh…

…en the left side was a constant.
  • Loading branch information...
commit 112651a282ccccb6054528dd88e667f1b9bff145 1 parent 63581ce
@craiggwilson craiggwilson authored
Showing with 30 additions and 2 deletions.
  1. +30 −2 source/MongoDB/Linq/Translators/QueryBinder.cs
View
32 source/MongoDB/Linq/Translators/QueryBinder.cs
@@ -36,9 +36,37 @@ public Expression Bind(Expression expression)
protected override Expression VisitBinary(BinaryExpression b)
{
+ ExpressionType nodeType = b.NodeType;
+ bool shouldFlip = false;
+ switch (nodeType)
+ {
+ case ExpressionType.LessThan:
+ nodeType = ExpressionType.GreaterThanOrEqual;
+ shouldFlip = true;
+ break;
+ case ExpressionType.LessThanOrEqual:
+ nodeType = ExpressionType.GreaterThan;
+ shouldFlip = true;
+ break;
+ case ExpressionType.GreaterThan:
+ nodeType = ExpressionType.LessThanOrEqual;
+ shouldFlip = true;
+ break;
+ case ExpressionType.GreaterThanOrEqual:
+ nodeType = ExpressionType.LessThan;
+ shouldFlip = true;
+ break;
+ case ExpressionType.NotEqual:
+ shouldFlip = true;
+ break;
+ case ExpressionType.Equal:
+ shouldFlip = true;
+ break;
+ }
+
//reverse the conditionals if the left one is a constant to make things easier in the formatter...
- if (b.Left.NodeType == ExpressionType.Constant)
- b = Expression.MakeBinary(b.NodeType, b.Right, b.Left, b.IsLiftedToNull, b.Method, b.Conversion);
+ if (shouldFlip && b.Left.NodeType == ExpressionType.Constant)
+ b = Expression.MakeBinary(nodeType, b.Right, b.Left, b.IsLiftedToNull, b.Method, b.Conversion);
return base.VisitBinary(b);
}
Please sign in to comment.
Something went wrong with that request. Please try again.