示例#1
0
        public override Expression GetUpdateExpression(IMappedEntity entity, Expression instance, LambdaExpression updateCheck, LambdaExpression selector)
        {
            var IdentifiableAlias = new IdentifiableAlias();
            var table = new IdentifiableExpression(IdentifiableAlias, entity, ((OTypeMapping)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.GetFieldAssignments(table, instance, entity, (e, m) => ((OTypeMapping)this.Mapping).IsUpdatable(e, m));

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

            if (selector != null)
            {
                return CreateUpdateCommand(entity, instance, selector, where, assignments);
            }
            else
            {
                return update;
            }
        }
示例#2
0
        protected override Expression VisitUpdate(UpdateCommandExpression update)
        {
            var oUpdate = update as OUpdateCommandExpression;
            if (oUpdate == null) return base.VisitUpdate(update);

            var table = (IdentifiableExpression)this.Visit(update.Identifiable);
            var where = this.Visit(update.Where);
            var assignments = this.VisitFieldAssignments(update.Assignments);
            var projection = this.VisitProjection(oUpdate.Projection);
            return this.UpdateUpdate(oUpdate, table, where, assignments, (ProjectionExpression)projection);
        }
示例#3
0
 protected virtual Expression VisitUpdate(UpdateCommandExpression update)
 {
     var table = (IdentifiableExpression)this.Visit(update.Identifiable);
     var where = this.Visit(update.Where);
     var assignments = this.VisitFieldAssignments(update.Assignments);
     return this.UpdateUpdate(update, table, where, assignments);
 }
示例#4
0
 protected UpdateCommandExpression UpdateUpdate(UpdateCommandExpression update, IdentifiableExpression table, Expression where, IEnumerable<FieldAssignment> assignments)
 {
     if (table != update.Identifiable || where != update.Where || assignments != update.Assignments)
     {
         return new UpdateCommandExpression(table, where, assignments);
     }
     return update;
 }
示例#5
0
        public override Expression GetUpdateExpression(IMappedEntity entity, Expression instance, LambdaExpression updateCheck, LambdaExpression selector)
        {
            var IdentifiableAlias = new IdentifiableAlias();
            var table = new IdentifiableExpression(IdentifiableAlias, 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.GetFieldAssignments(table, instance, entity, (e, m) => this.mapping.IsUpdatable(e, m));

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

            if (selector != null)
            {
                return new BlockCommandExpression(
                    update,
                    new IfCommandExpression(
                        this.translator.Linguist.Language.GetRowsAffectedExpression(update).GreaterThan(Expression.Constant(0)),
                        this.GetUpdateResult(entity, instance, selector),
                        null
                        )
                    );
            }
            else
            {
                return update;
            }
        }
示例#6
0
 protected override Expression VisitUpdate(UpdateCommandExpression update)
 {
     this.Write("UPDATE ");
     this.WriteIdentifiableName(update.Identifiable.Name);
     this.WriteLine(Indentation.Same);
     bool saveHide = this.HideFieldAliases;
     this.HideFieldAliases = true;
     this.Write("SET ");
     for (int i = 0, n = update.Assignments.Count; i < n; i++)
     {
          FieldAssignment ca = update.Assignments[i];
         if (i > 0) this.Write(", ");
         this.Visit(ca. Field);
         this.Write(" = ");
         this.Visit(ca.Expression);
     }
     if (update.Where != null)
     {
         this.WriteLine(Indentation.Same);
         this.Write("WHERE ");
         this.VisitPredicate(update.Where);
     }
     this.HideFieldAliases = saveHide;
     return update;
 }
示例#7
0
 protected virtual bool CompareUpdate(UpdateCommandExpression x, UpdateCommandExpression y)
 {
     return this.Compare(x.Identifiable, y.Identifiable) && this.Compare(x.Where, y.Where) && this.CompareFieldAssignments(x.Assignments, y.Assignments);
 }