protected virtual Expression VisitIn(InExpression @in) { var expr = this.Visit(@in.Expression); var select = (SelectExpression)this.Visit(@in.Select); var values = this.VisitExpressionList(@in.Values); return this.UpdateIn(@in, expr, select, values); }
protected InExpression UpdateIn(InExpression @in, Expression expression, SelectExpression select, IEnumerable<Expression> values) { if (expression != @in.Expression || select != @in.Select || values != @in.Values) { if (select != null) { return new InExpression(expression, select); } else { return new InExpression(expression, values); } } return @in; }
protected virtual bool CompareIn(InExpression a, InExpression b) { return this.Compare(a.Expression, b.Expression) && this.Compare(a.Select, b.Select) && this.CompareExpressionList(a.Values, b.Values); }
protected override Expression VisitIn(InExpression @in) { if (@in.Values != null) { if (@in.Values.Count == 0) { this.Write("0 <> 0"); } else { this.VisitValue(@in.Expression); this.Write(" IN ("); for (int i = 0, n = @in.Values.Count; i < n; i++) { if (i > 0) this.Write(", "); this.VisitValue(@in.Values[i]); } this.Write(")"); } } else { this.VisitValue(@in.Expression); this.Write(" IN ("); this.WriteLine(Indentation.Inner); this.Visit(@in.Select); this.WriteLine(Indentation.Same); this.Write(")"); this.Indent(Indentation.Outer); } return @in; }
private Expression BindContains(Expression source, Expression match, bool isRoot) { ConstantExpression constSource = source as ConstantExpression; if (constSource != null && !IsQuery(constSource)) { System.Diagnostics.Debug.Assert(!isRoot); List<Expression> values = new List<Expression>(); foreach (object value in (IEnumerable)constSource.Value) { values.Add(Expression.Constant(Convert.ChangeType(value, match.Type), match.Type)); } match = this.Visit(match); return new InExpression(match, values); } else if (isRoot && !this.language.AllowSubqueryInSelectWithoutFrom) { var p = Expression.Parameter(TypeHelper.GetElementType(source.Type), "x"); var predicate = Expression.Lambda(p.Equal(match), p); var exp = Expression.Call(typeof(Queryable), "Any", new Type[] { p.Type }, source, predicate); this.root = exp; return this.Visit(exp); } else { ProjectionExpression projection = this.VisitSequence(source); match = this.Visit(match); Expression result = new InExpression(match, projection.Select); if (isRoot) { return this.GetSingletonSequence(result, "SingleOrDefault"); } return result; } }