Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Commit

Permalink
fixed a nasty bug related to flipping binary comparison operations wh…
Browse files Browse the repository at this point in the history
…en the left side was a constant.
  • Loading branch information
craiggwilson committed Jun 27, 2010
1 parent 63581ce commit 112651a
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions source/MongoDB/Linq/Translators/QueryBinder.cs
Expand Up @@ -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);
}
Expand Down

0 comments on commit 112651a

Please sign in to comment.