Beispiel #1
0
        protected override DbColumnAssignment VisitColumnAssignment(DbColumnAssignment ca)
        {
            ca = base.VisitColumnAssignment(ca);
            Expression             expression = ca.Expression;
            DbNamedValueExpression nv         = expression as DbNamedValueExpression;

            if (nv != null)
            {
                expression = new DbNamedValueExpression(nv.Name, ca.Column.DbType, nv.Value);
            }
            return(this.UpdateColumnAssignment(ca, ca.Column, expression));
        }
Beispiel #2
0
        protected override Expression VisitMemberAccess(MemberExpression m)
        {
            m = (MemberExpression)base.VisitMemberAccess(m);
            DbNamedValueExpression nv = m.Expression as DbNamedValueExpression;

            if (nv != null)
            {
                Expression x = Expression.MakeMemberAccess(nv.Value, m.Member);
                return(GetNamedValue(x));
            }
            return(m);
        }
Beispiel #3
0
        private Expression GetNamedValue(Expression e)
        {
            DbNamedValueExpression nv;
            HashedExpression       he = new HashedExpression(e);

            if (!this.pmap.TryGetValue(he, out nv))
            {
                string name = "p" + (iParam++);
                nv = new DbNamedValueExpression(name, this.language.TypeSystem.GetColumnType(e.Type), e);
                this.pmap.Add(he, nv);
            }
            return(nv);
        }
Beispiel #4
0
 protected override Expression VisitColumn(DbColumnExpression column)
 {
     if (column.Alias == this.outerAlias)
     {
         DbNamedValueExpression nv;
         if (!this.map.TryGetValue(column, out nv))
         {
             nv = new DbNamedValueExpression("n" + (iParam++), column.DbType, column);
             this.map.Add(column, nv);
         }
         return(nv);
     }
     return(column);
 }
Beispiel #5
0
 protected override Expression VisitConstant(ConstantExpression c)
 {
     if (c.Value != null && !IsNumeric(c.Value.GetType()))
     {
         DbNamedValueExpression nv;
         if (!this.map.TryGetValue(c.Value, out nv))   // re-use same name-value if same value
         {
             string name = "p" + (iParam++);
             nv = new DbNamedValueExpression(name, this.language.TypeSystem.GetColumnType(c.Type), c);
             this.map.Add(c.Value, nv);
         }
         return(nv);
     }
     return(c);
 }
Beispiel #6
0
        protected override Expression VisitBinary(BinaryExpression b)
        {
            Expression left  = this.Visit(b.Left);
            Expression right = this.Visit(b.Right);

            if (left.NodeType == (ExpressionType)DbExpressionType.NamedValue &&
                right.NodeType == (ExpressionType)DbExpressionType.Column)
            {
                DbNamedValueExpression nv = (DbNamedValueExpression)left;
                DbColumnExpression     c  = (DbColumnExpression)right;
                left = new DbNamedValueExpression(nv.Name, c.DbType, nv.Value);
            }
            else if (b.Right.NodeType == (ExpressionType)DbExpressionType.NamedValue &&
                     b.Left.NodeType == (ExpressionType)DbExpressionType.Column)
            {
                DbNamedValueExpression nv = (DbNamedValueExpression)right;
                DbColumnExpression     c  = (DbColumnExpression)left;
                right = new DbNamedValueExpression(nv.Name, c.DbType, nv.Value);
            }
            return(this.UpdateBinary(b, left, right, b.Conversion, b.IsLiftedToNull, b.Method));
        }
Beispiel #7
0
        protected override Expression VisitDeclaration(DbDeclaration decl)
        {
            if (decl.Source != null)
            {
                // make query that returns all these declared values as an object[]
                var projection = new DbProjectionExpression(
                    decl.Source,
                    Expression.NewArrayInit(
                        typeof(object),
                        decl.Variables.Select(v => v.Expression.Type.IsValueType
                            ? Expression.Convert(v.Expression, typeof(object))
                            : v.Expression).ToArray()
                        ),
                    Aggregator.Aggregate(typeof(object[]), typeof(IEnumerable <object[]>))
                    );

                // create execution variable to hold the array of declared variables
                var vars = Expression.Parameter(typeof(object[]), "vars");
                this.variables.Add(vars);
                this.initializers.Add(Expression.Constant(null, typeof(object[])));

                // create subsitution for each variable (so it will find the variable value in the new vars array)
                for (int i = 0, n = decl.Variables.Count; i < n; i++)
                {
                    var v = decl.Variables[i];
                    DbNamedValueExpression nv = new DbNamedValueExpression(
                        v.Name, v.DbType,
                        Expression.Convert(Expression.ArrayIndex(vars, Expression.Constant(i)), v.Expression.Type)
                        );
                    this.variableMap.Add(v.Name, nv);
                }

                // make sure the execution of the select stuffs the results into the new vars array
                return(MakeAssign(vars, this.Visit(projection)));
            }

            // probably bad if we get here since we must not allow mulitple commands
            throw new InvalidOperationException("Declaration query not allowed for this langauge");
        }
 protected virtual Expression VisitNamedValue(DbNamedValueExpression value)
 {
     return value;
 }
 protected virtual bool CompareNamedValue(DbNamedValueExpression a, DbNamedValueExpression b)
 {
     return(a.Name == b.Name && Compare(a.Value, b.Value));
 }
Beispiel #10
0
 protected override Expression VisitNamedValue(DbNamedValueExpression value)
 {
     this.namedValues.Add(value);
     return(value);
 }
 protected override Expression VisitNamedValue(DbNamedValueExpression value)
 {
     this.WriteParameterName(value.Name);
     return value;
 }
 protected virtual bool CompareNamedValue(DbNamedValueExpression a, DbNamedValueExpression b)
 {
     return a.Name == b.Name && Compare(a.Value, b.Value);
 }
Beispiel #13
0
 protected virtual Expression VisitNamedValue(DbNamedValueExpression value)
 {
     return(value);
 }