protected override Expression VisitDeclaration(DbDeclarationCommand decl)
        {
            if (decl.Source != null)
            {
                var projection = new DbProjectionExpression
                                 (
                    decl.Source,
                    Expression.NewArrayInit(typeof(object), decl.Variables.Select(v => v.Expression.Type.GetTypeInfo().IsValueType ? Expression.Convert(v.Expression, typeof(object)) : v.Expression).ToArray()),
                    DbAggregator.GetAggregator(typeof(object[]), typeof(IEnumerable <object[]>))
                                 );

                var vars = Expression.Parameter(typeof(object[]), "vars");

                this.variables.Add(vars);
                this.initializers.Add(Expression.Constant(null, typeof(object[])));

                for (int i = 0, n = decl.Variables.Count; i < n; i++)
                {
                    var v  = decl.Variables[i];
                    var nv = new DbNamedValueExpression
                             (
                        v.Name, v.QueryType,
                        Expression.Convert(Expression.ArrayIndex(vars, Expression.Constant(i)), v.Expression.Type)
                             );

                    this.variableMap.Add(v.Name, nv);
                }

                return(MakeAssign(vars, this.Visit(projection)));
            }

            throw new InvalidOperationException("Declaration query not allowed for this langauge");
        }
Esempio n. 2
0
        protected override DbColumnAssignment VisitColumnAssignment(DbColumnAssignment ca)
        {
            ca = base.VisitColumnAssignment(ca);

            var expression = ca.Expression;

            if (expression is DbNamedValueExpression nv)
            {
                expression = new DbNamedValueExpression(nv.Name, ca.Column.QueryType, nv.Value);
            }

            return(this.UpdateColumnAssignment(ca, ca.Column, expression));
        }
Esempio n. 3
0
        private Expression GetNamedValue(Expression e)
        {
            var he = new HashedExpression(e);

            if (this.pmap.TryGetValue(he, out DbNamedValueExpression nv) == false)
            {
                var name = "p" + (iParam++);

                nv = new DbNamedValueExpression(name, this.language.TypeSystem.GetColumnType(e.Type), e);

                this.pmap.Add(he, nv);
            }

            return(nv);
        }
Esempio n. 4
0
        protected override Expression VisitConstant(ConstantExpression c)
        {
            if (c.Value != null && !IsNumeric(c.Value.GetType()))
            {
                var tv = new TypeAndValue(c.Type, c.Value);

                if (this.map.TryGetValue(tv, out DbNamedValueExpression nv) == false)
                {
                    var name = "p" + (iParam++);

                    nv = new DbNamedValueExpression(name, this.language.TypeSystem.GetColumnType(c.Type), c);

                    this.map.Add(tv, nv);
                }

                return(nv);
            }

            return(c);
        }
Esempio n. 5
0
        protected override Expression VisitBinary(BinaryExpression b)
        {
            var left  = this.Visit(b.Left);
            var right = this.Visit(b.Right);

            if (left.NodeType == (ExpressionType)DbExpressionType.NamedValue && right.NodeType == (ExpressionType)DbExpressionType.Column)
            {
                var nv = left as DbNamedValueExpression;
                var c  = right as DbColumnExpression;

                left = new DbNamedValueExpression(nv.Name, c.QueryType, nv.Value);
            }
            else if (right.NodeType == (ExpressionType)DbExpressionType.NamedValue && left.NodeType == (ExpressionType)DbExpressionType.Column)
            {
                var nv = right as DbNamedValueExpression;
                var c  = left as DbColumnExpression;

                right = new DbNamedValueExpression(nv.Name, c.QueryType, nv.Value);
            }

            return(this.UpdateBinary(b, left, right, b.Conversion, b.IsLiftedToNull, b.Method));
        }
 protected virtual bool CompareNamedValue(DbNamedValueExpression a, DbNamedValueExpression b)
 {
     return(a.Name == b.Name && this.Compare(a.Value, b.Value));
 }
Esempio n. 7
0
        protected override Expression VisitNamedValue(DbNamedValueExpression value)
        {
            this.WriteParameterName(value.Name);

            return(value);
        }
 protected virtual Expression VisitNamedValue(DbNamedValueExpression value)
 {
     return(value);
 }
Esempio n. 9
0
        protected override Expression VisitNamedValue(DbNamedValueExpression value)
        {
            this.namedValues.Add(value);

            return(value);
        }