public Expression ComparisonExpression(ComparisonExpression expression) { var left = expression.Left.Visit(this); var right = expression.Right.Visit(this); var leftLiteral = left as LiteralExpression; var rightLiteral = right as LiteralExpression; if (leftLiteral != null && rightLiteral != null) { return(ResolveComparisonLiterals(expression, leftLiteral, rightLiteral)); } return(new ComparisonExpression(expression.Operator, left, right)); }
private Expression ResolveComparisonLiterals(ComparisonExpression expression, LiteralExpression leftLiteral, LiteralExpression rightLiteral) { object left = leftLiteral.Value; object right = rightLiteral.Value; bool result; var type = LiteralUtil.CoerceLiteralValues(ref left, leftLiteral.LiteralType, ref right, rightLiteral.LiteralType); switch (expression.Operator) { case Operator.Eq: result = ResolveEquals(left, right, type); break; case Operator.Ne: result = !ResolveEquals(left, right, type); break; case Operator.Gt: result = ResolveCompare(left, right, type) > 0; break; case Operator.Ge: result = ResolveCompare(left, right, type) >= 0; break; case Operator.Lt: result = ResolveCompare(left, right, type) < 0; break; case Operator.Le: result = ResolveCompare(left, right, type) <= 0; break; default: throw new NotSupportedException(); } return(new LiteralExpression(result, LiteralType.Boolean)); }
public Expression ComparisonExpression(ComparisonExpression expression) { Operator op = expression.Operator; switch (op) { case Operator.Gt: op = Operator.Le; break; case Operator.Ge: op = Operator.Lt; break; case Operator.Lt: op = Operator.Ge; break; case Operator.Le: op = Operator.Gt; break; case Operator.Eq: op = Operator.Ne; break; case Operator.Ne: op = Operator.Eq; break; default: throw new NotSupportedException(); } return(new ComparisonExpression(op, expression.Left.Visit(this), expression.Right.Visit(this))); }
public virtual T ComparisonExpression(ComparisonExpression expression) { throw new QueryNotSupportException(); }
public override ICriterion ComparisonExpression(ComparisonExpression expression) { IProjection left; IProjection right; var leftExpression = expression.Left; var rightExpression = expression.Right; // Swap the expressions if the left operand is null. if (IsNull(leftExpression)) { var tmp = leftExpression; leftExpression = rightExpression; rightExpression = tmp; } if (IsNull(rightExpression)) { if (IsNull(leftExpression)) { throw new NotSupportedException(); } left = ProjectionVisitor.CreateProjection(leftExpression); // If the restriction is applied to a component ("Component eq null"), // we should use Restrictions.IsNull(string propertyName) overload, otherwise NHibernate will raise an exception IPropertyProjection property = left as IPropertyProjection; if (property != null) { switch (expression.Operator) { case Operator.Eq: return(Restrictions.IsNull(property.PropertyName)); case Operator.Ne: return(Restrictions.IsNotNull(property.PropertyName)); } } else { switch (expression.Operator) { case Operator.Eq: return(Restrictions.IsNull(left)); case Operator.Ne: return(Restrictions.IsNotNull(left)); } } throw new NotSupportedException(); } left = ProjectionVisitor.CreateProjection(expression.Left); right = ProjectionVisitor.CreateProjection(expression.Right); switch (expression.Operator) { case Operator.Eq: return(Restrictions.EqProperty(left, right)); case Operator.Ne: return(Restrictions.NotEqProperty(left, right)); case Operator.Gt: return(Restrictions.GtProperty(left, right)); case Operator.Ge: return(Restrictions.GeProperty(left, right)); case Operator.Lt: return(Restrictions.LtProperty(left, right)); case Operator.Le: return(Restrictions.LeProperty(left, right)); default: throw new NotSupportedException(); } }