private ContainsExpression VisitContains(MethodCallExpression expression) { // Handle extension methods defined by Linqs if (IsDeclaring(expression, typeof(Queryable), typeof(Enumerable))) { AExpression values = Visit <AExpression>(expression.Arguments[0]); AExpression value = Visit <AExpression>(expression.Arguments[1]); return(new ContainsExpression(values, value)); } // Handle custom extension method if (IsDeclaring(expression, typeof(SqlQueryableHelper))) { // Get value expression first, because the source will change to the subquery making the value out of scope AExpression value = Visit <AExpression>(expression.Arguments[2]); // Evaluate the subquery expressions ASourceExpression source = Visit <ASourceExpression>(expression.Arguments[0]); LambdaExpression fieldLambda = (LambdaExpression)StripQuotes(expression.Arguments[1]); FieldExpression field = Visit <FieldExpression>(fieldLambda.Body); // Create the expression return(new ContainsExpression(new ScalarExpression(source, field), value)); } throw new MethodTranslationException(expression.Method); }
/// <summary> /// Visits the children of the System.Linq.Expressions.BinaryExpression. This implementation converts the expression into a <see cref="CompositeExpression"/>. /// </summary> /// <param name="node">The expression to visit</param> /// <returns>The specified binary expression converted to a <see cref="CompositeExpression"/>.</returns> protected override Expression VisitBinary(BinaryExpression node) { AExpression left = Visit <AExpression>(node.Left); AExpression right = Visit <AExpression>(node.Right); return(new CompositeExpression(left, right, GetCompositeOperator(node.NodeType))); }
/// <summary> /// Initializes a new instance of <see cref="ContainsExpression"/> with the specified values and value expressions. /// </summary> /// <param name="values">An expression representing a sequence of values.</param> /// <param name="value">The expression representing a value that should be searched for in the values.</param> public ContainsExpression(AExpression values, AExpression value) { if (values == null) { throw new ArgumentNullException(nameof(values)); } if (value == null) { throw new ArgumentNullException(nameof(value)); } Values = values; Value = value; }
/// <summary> /// Initializes a new instance of <see cref="CompositeExpression"/>, with the specified left, right and operator arguments. /// </summary> /// <param name="left">The left hand expression to compare.</param> /// <param name="right">The right hand expression to compare.</param> /// <param name="type">The operator to use when comparing the left and right hand predicates.</param> public CompositeExpression(AExpression left, AExpression right, CompositeOperator type = CompositeOperator.And) { if (left == null) { throw new ArgumentNullException(nameof(left)); } if (right == null) { throw new ArgumentNullException(nameof(right)); } Left = left; Right = right; Operator = type; }
/// <summary> /// Initializes a new instance of <see cref="FieldExpression"/>, selecting the specified field from the specified source. /// </summary> /// <param name="valueExpression">The fields <see cref="AExpression"/> representing the value of the field.</param> /// <param name="table">The table or table alias the field is exposed from.</param> /// <param name="field">The name of the field on the source.</param> /// <param name="sourceExpression">The optional field expression this instance is mapping.</param> public FieldExpression(AExpression valueExpression, string table, string field, FieldExpression sourceExpression = null) { if (valueExpression == null) { throw new ArgumentNullException(nameof(valueExpression)); } if (string.IsNullOrWhiteSpace(table)) { throw new ArgumentException("Cannot be whitespace.", nameof(table)); } if (string.IsNullOrWhiteSpace(field)) { throw new ArgumentException("Cannot be whitespace.", nameof(field)); } ValueExpression = valueExpression; TableName = table; FieldName = field; SourceExpression = sourceExpression; }