Пример #1
0
        protected override Expression VisitMemberAccess(MemberExpression m)
        {
            m = (MemberExpression)base.VisitMemberAccess(m);
            NamedValueExpression nv = m.Expression as NamedValueExpression;

            if (nv != null)
            {
                Expression x = Expression.MakeMemberAccess(nv.Value, m.Member);
                return(GetNamedValue(x));
            }
            return(m);
        }
Пример #2
0
        private Expression GetNamedValue(Expression e)
        {
            NamedValueExpression nv;
            HashedExpression     he = new HashedExpression(e);

            if (!this.pmap.TryGetValue(he, out nv))
            {
                string name = "p" + (iParam++);
                nv = new NamedValueExpression(name, SqlType.Get(e.Type), e);
                this.pmap.Add(he, nv);
            }
            return(nv);
        }
Пример #3
0
        protected override ColumnAssignment VisitColumnAssignment(ColumnAssignment ca)
        {
            ca = base.VisitColumnAssignment(ca);
            Expression           expression = ca.Expression;
            NamedValueExpression nv         = null;

            if (expression.NodeType == ExpressionType.Constant)
            {
                var value = (expression as ConstantExpression).Value;
                if (value == null)
                {
                    TypeAndValue tv = new TypeAndValue(ca.Column.Type, null);
                    if (!this.map.TryGetValue(tv, out nv))
                    {
                        string name = "p" + (iParam++);
                        nv = new NamedValueExpression(name, SqlType.Get(ca.Column.Type), Expression.Constant(null, ca.Column.Type));
                        this.map.Add(tv, nv);
                    }
                    expression = nv;
                }
                else
                {
                    var columnType = ca.Column.Type;
                    if (columnType.IsNullable())
                    {
                        columnType = Nullable.GetUnderlyingType(columnType);
                    }

                    if (columnType != value.GetType())
                    {
                        value      = Converter.Convert(value, columnType);
                        expression = Expression.Constant(value);
                    }
                }
            }

            nv = expression as NamedValueExpression;
            if (nv != null)
            {
                expression = new NamedValueExpression(nv.Name, ca.Column.SqlType, nv.Value);
            }
            return(this.UpdateColumnAssignment(ca, ca.Column, expression));
        }
Пример #4
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)
            {
                NamedValueExpression nv = (NamedValueExpression)left;
                ColumnExpression     c  = (ColumnExpression)right;
                left = new NamedValueExpression(nv.Name, c.SqlType, nv.Value);
            }
            else if (right.NodeType == (ExpressionType)DbExpressionType.NamedValue &&
                     left.NodeType == (ExpressionType)DbExpressionType.Column)
            {
                NamedValueExpression nv = (NamedValueExpression)right;
                ColumnExpression     c  = (ColumnExpression)left;
                right = new NamedValueExpression(nv.Name, c.SqlType, nv.Value);
            }
            return(this.UpdateBinary(b, left, right, b.Conversion, b.IsLiftedToNull, b.Method));
        }
Пример #5
0
        protected override Expression VisitConstant(ConstantExpression c)
        {
            if (c.Value != null)
            {
                var type = c.Value.GetType();
                if (/*!IsNumeric(type) && type != Types.TimeSpan &&*/ c.Type != typeof(Type))
                {
                    NamedValueExpression nv;
                    TypeAndValue         tv = new TypeAndValue(type, c.Value);
                    if (!this.map.TryGetValue(tv, out nv))
                    {
                        string name = "p" + (iParam++);
                        nv = new NamedValueExpression(name, SqlType.Get(type), c);
                        this.map.Add(tv, nv);
                    }
                    return(nv);
                }
                //else
                //{

                //}
            }
            return(c);
        }
Пример #6
0
 protected virtual bool CompareNamedValue(NamedValueExpression a, NamedValueExpression b)
 {
     return(a.Name == b.Name && this.Compare(a.Value, b.Value));
 }
Пример #7
0
 protected override Expression VisitNamedValue(NamedValueExpression value)
 {
     this.namedValues.Add(value);
     return(value);
 }
Пример #8
0
 protected virtual Expression VisitNamedValue(NamedValueExpression value)
 {
     return(value);
 }