Ejemplo n.º 1
0
        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 DbInExpression(match, values));
            }
            else if (isRoot && !this.mapping.Language.AllowSubqueryInSelectWithoutFrom)
            {
                var p         = Expression.Parameter(source.Type.GetSequenceElementType(), "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
            {
                DbProjectionExpression projection = this.VisitSequence(source);
                match = this.Visit(match);
                Expression result = new DbInExpression(match, projection.Select);
                if (isRoot)
                {
                    return(this.GetSingletonSequence(result, "SingleOrDefault"));
                }
                return(result);
            }
        }
Ejemplo n.º 2
0
        protected virtual Expression VisitIn(DbInExpression ixp)
        {
            Expression         expr   = Visit(ixp.Expression);
            DbSelectExpression select = (DbSelectExpression)Visit(ixp.Select);
            ReadOnlyCollection <Expression> values = VisitExpressionList(ixp.Values);

            return(UpdateIn(ixp, expr, select, values));
        }
Ejemplo n.º 3
0
        protected DbInExpression UpdateIn(DbInExpression ixp, Expression expression,
                                          DbSelectExpression select, IEnumerable <Expression> values)
        {
            if (expression != ixp.Expression ||
                select != ixp.Select || values != ixp.Values)
            {
                if (select != null)
                {
                    return(new DbInExpression(expression, select));
                }

                return(new DbInExpression(expression, values));
            }
            return(ixp);
        }
 protected DbInExpression UpdateIn(DbInExpression ixp, Expression expression, 
     DbSelectExpression select, IEnumerable<Expression> values)
 {
     if (expression != ixp.Expression || 
         select != ixp.Select || values != ixp.Values)
     {
         if (select != null)
             return new DbInExpression(expression, select);
         
         return new DbInExpression(expression, values);
     }
     return ixp;
 }
        protected virtual Expression VisitIn(DbInExpression ixp)
        {
            Expression expr = Visit(ixp.Expression);
            DbSelectExpression select = (DbSelectExpression)Visit(ixp.Select);
            ReadOnlyCollection<Expression> values = VisitExpressionList(ixp.Values);

            return UpdateIn(ixp, expr, select, values);
        }
 protected virtual bool CompareIn(DbInExpression a, DbInExpression b)
 {
     return(Compare(a.Expression, b.Expression) &&
            Compare(a.Select, b.Select) &&
            CompareExpressionList(a.Values, b.Values));
 }
Ejemplo n.º 7
0
 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 DbInExpression(match, values);
     }
     else if (isRoot && !this.mapping.Language.AllowSubqueryInSelectWithoutFrom)
     {
         var p = Expression.Parameter(source.Type.GetSequenceElementType(), "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 
     {
         DbProjectionExpression projection = this.VisitSequence(source);
         match = this.Visit(match);
         Expression result = new DbInExpression(match, projection.Select);
         if (isRoot)
         {
             return this.GetSingletonSequence(result, "SingleOrDefault");
         }
         return result;
     }
 }
Ejemplo n.º 8
0
 protected override Expression VisitIn(DbInExpression @in)
 {
     this.VisitValue(@in.Expression);
     this.Write(" IN (");
     if (@in.Select != null)
     {
         this.WriteLine(Indentation.Inner);
         this.Visit(@in.Select);
         this.WriteLine(Indentation.Same);
         this.Write(")");
         this.Indent(Indentation.Outer);
     }
     else if (@in.Values != null)
     {
         for (int i = 0, n = @in.Values.Count; i < n; i++)
         {
             if (i > 0) this.Write(", ");
             this.VisitValue(@in.Values[i]);
         }
         this.Write(")");
     }
     return @in;
 }
 protected virtual bool CompareIn(DbInExpression a, DbInExpression b)
 {
     return Compare(a.Expression, b.Expression)
         && Compare(a.Select, b.Select)
         && CompareExpressionList(a.Values, b.Values);
 }