private void VisitEqual(BinaryExpressionHandler node) { if (node.HasPropertyExpression && node.PropertyExpression.Expression.NodeType == ExpressionType.Parameter) { var name = node.PropertyExpression.Member.Name; var value = EvalValue(node.ValueExpression); Query = new QueryContainer(new TermQuery() { Field = (value is string?$"{name}.keyword" : name), Value = value }); return; } throw new NotSupportedException("Not support this expression:" + node); }
private void VisitLessThanOrEqual(BinaryExpressionHandler node, bool containEqual = false) { if (node.HasPropertyExpression && node.PropertyExpression.Expression.NodeType == ExpressionType.Parameter) { var name = node.PropertyExpression.Member.Name; dynamic value = EvalValue(node.ValueExpression); if (node.IsRight) { Query = GreaterThanOrEqual(name, value, containEqual); } else { Query = LowerThanOrEqual(name, value, containEqual); } } }
protected override Expression VisitBinary(BinaryExpression node) { var handler = new BinaryExpressionHandler(node); switch (node.NodeType) { case ExpressionType.And: case ExpressionType.AndAlso: VisitAnd(node); break; case ExpressionType.Or: case ExpressionType.OrElse: VisitOr(node); break; case ExpressionType.Equal: VisitEqual(handler); break; case ExpressionType.NotEqual: VisitNotEqual(handler); break; case ExpressionType.LessThan: VisitLessThanOrEqual(handler); break; case ExpressionType.LessThanOrEqual: VisitLessThanOrEqual(handler, true); break; case ExpressionType.GreaterThan: VisitGreaterThanOrEqual(handler); break; case ExpressionType.GreaterThanOrEqual: VisitGreaterThanOrEqual(handler, true); break; default: throw new NotSupportedException(string.Format("The binary operator ‘{0}’ is not supported", node.NodeType)); } return(node); }