示例#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);
        }
示例#2
0
 protected PartialUpdateCommand UpdatePartialUpdate(PartialUpdateCommand update, TableExpression table, Expression where, IEnumerable <ColumnAssignment> assignments)
 {
     if (table != update.Table || where != update.Where || assignments != update.Assignments)
     {
         return(new PartialUpdateCommand(table, where, assignments));
     }
     return(update);
 }
示例#3
0
        protected virtual Expression VisitPartialUpdate(PartialUpdateCommand update)
        {
            var table = (TableExpression)this.Visit(update.Table);

            var where = this.Visit(update.Where);
            var assignments = this.VisitColumnAssignments(update.Assignments);

            return(this.UpdatePartialUpdate(update, table, where, assignments));
        }
示例#4
0
        //protected override Expression VisitInsert(InsertCommand insert)
        //{
        //    return this.BuildExecuteCommand(insert);
        //}

        //protected override Expression VisitUpdate(UpdateCommand update)
        //{
        //    return this.BuildExecuteCommand(update);
        //}

        protected override Expression VisitPartialUpdate(PartialUpdateCommand update)
        {
            var pcmd  = update as PartialUpdateCommand;
            var table = pcmd.Table;

            var where = pcmd.Where;
            var assignments = pcmd.Assignments.Where(ca => (ca.Expression as ConstantExpression).Value != null).ToList();

            pcmd = this.UpdatePartialUpdate(update, table, where, assignments);
            return(this.BuildExecuteCommand(pcmd));
        }
示例#5
0
        public override Expression GetPartialUpdateExpression(MappingEntity entity, Expression instance, LambdaExpression updateCheck, LambdaExpression selector, Expression @else)
        {
            var tableAlias = new TableAlias();
            var table      = new TableExpression(tableAlias, entity, this.mapping.GetTableName(entity));

            var where = this.GetIdentityCheck(table, entity, instance);
            if (updateCheck != null)
            {
                Expression typeProjector = this.GetEntityExpression(table, entity);
                Expression pred          = DbExpressionReplacer.Replace(updateCheck.Body, updateCheck.Parameters[0], typeProjector);
                where = where.And(pred);
            }

            var assignments = this.GetColumnAssignments(table, instance, entity, (e, m) => this.mapping.IsUpdatable(e, m));

            Expression update = new PartialUpdateCommand(table, where, assignments);

            if (selector != null)
            {
                return(new BlockCommand(
                           update,
                           new IFCommand(
                               this.translator.Linguist.Language.GetRowsAffectedExpression(update).GreaterThan(Expression.Constant(0)),
                               this.GetUpdateResult(entity, instance, selector),
                               @else
                               )
                           ));
            }
            else if (@else != null)
            {
                return(new BlockCommand(
                           update,
                           new IFCommand(
                               this.translator.Linguist.Language.GetRowsAffectedExpression(update).LessThanOrEqual(Expression.Constant(0)),
                               @else,
                               null
                               )
                           ));
            }
            else
            {
                return(update);
            }
        }
示例#6
0
 protected virtual bool ComparePartialUpdate(PartialUpdateCommand x, PartialUpdateCommand y)
 {
     return(this.Compare(x.Table, y.Table) && this.Compare(x.Where, y.Where) && this.CompareColumnAssignments(x.Assignments, y.Assignments));
 }