Example #1
0
        protected override Expression VisitPartialUpdate(PartialUpdateCommand update)
        {
            this.Write("UPDATE ");
            this.WriteTableName(update.Table.Name);
            this.WriteLine(Indentation.Same);
            bool saveHide = this.HideColumnAliases;

            this.HideColumnAliases = true;
            this.Write("SET ");
            for (int i = 0, n = update.Assignments.Count; i < n; i++)
            {
                ColumnAssignment ca = update.Assignments[i];
                if (i > 0)
                {
                    this.Write(", ");
                }
                this.Visit(ca.Column);
                this.Write(" = ");
                this.Visit(ca.Expression);
            }
            if (update.Where != null)
            {
                this.WriteLine(Indentation.Same);
                this.Write("WHERE ");
                this.VisitPredicate(update.Where);
            }
            this.HideColumnAliases = saveHide;
            return(update);
        }
Example #2
0
 protected override Expression VisitInsert(InsertCommand insert)
 {
     this.Write("INSERT INTO ");
     this.WriteTableName(insert.Table.Name);
     this.Write("(");
     for (int i = 0, n = insert.Assignments.Count; i < n; i++)
     {
         ColumnAssignment ca = insert.Assignments[i];
         if (i > 0)
         {
             this.Write(", ");
         }
         this.WriteColumnName(ca.Column.Name);
     }
     this.Write(")");
     this.WriteLine(Indentation.Same);
     this.Write("VALUES (");
     for (int i = 0, n = insert.Assignments.Count; i < n; i++)
     {
         ColumnAssignment ca = insert.Assignments[i];
         if (i > 0)
         {
             this.Write(", ");
         }
         this.Visit(ca.Expression);
     }
     this.Write(")");
     return(insert);
 }
Example #3
0
        protected virtual ColumnAssignment VisitColumnAssignment(ColumnAssignment ca)
        {
            ColumnExpression c = (ColumnExpression)this.Visit(ca.Column);
            Expression       e = this.Visit(ca.Expression);

            return(this.UpdateColumnAssignment(ca, c, e));
        }
Example #4
0
 protected ColumnAssignment UpdateColumnAssignment(ColumnAssignment ca, ColumnExpression c, Expression e)
 {
     if (c != ca.Column || e != ca.Expression)
     {
         return(new ColumnAssignment(c, e));
     }
     return(ca);
 }
Example #5
0
        protected override ColumnAssignment VisitColumnAssignment(ColumnAssignment ca)
        {
            ca = base.VisitColumnAssignment(ca);
            Expression           expression = ca.Expression;
            NamedValueExpression nv         = expression as NamedValueExpression;

            if (nv != null)
            {
                expression = new NamedValueExpression(ca.Column.Name, ca.Column.QueryType, nv.Value);
            }
            return(this.UpdateColumnAssignment(ca, ca.Column, expression));
        }
Example #6
0
        protected virtual ReadOnlyCollection <ColumnAssignment> VisitColumnAssignments(ReadOnlyCollection <ColumnAssignment> assignments)
        {
            List <ColumnAssignment> alternate = null;

            for (int i = 0, n = assignments.Count; i < n; i++)
            {
                ColumnAssignment assignment = this.VisitColumnAssignment(assignments[i]);
                if (alternate == null && assignment != assignments[i])
                {
                    alternate = assignments.Take(i).ToList();
                }
                if (alternate != null)
                {
                    alternate.Add(assignment);
                }
            }
            if (alternate != null)
            {
                return(alternate.AsReadOnly());
            }
            return(assignments);
        }