protected DbUpdateCommand UpdateUpdate(DbUpdateCommand update, DbTableExpression table, Expression where, IEnumerable <DbColumnAssignment> assignments) { if (table != update.Table || where != update.Where || assignments != update.Assignments) { return(new DbUpdateCommand(table, where, assignments)); } return(update); }
protected virtual Expression VisitUpdate(DbUpdateCommand update) { var table = this.Visit(update.Table) as DbTableExpression; var where = this.Visit(update.Where); var assignments = this.VisitColumnAssignments(update.Assignments); return(this.UpdateUpdate(update, table, where, assignments)); }
public override Expression GetUpdateExpression(MappingEntity entity, Expression instance, LambdaExpression updateCheck, LambdaExpression selector, Expression exp) { var tableAlias = new TableAlias(); var table = new DbTableExpression(tableAlias, entity, this.mapping.GetTableName(entity)); var where = this.GetIdentityCheck(table, entity, instance); if (updateCheck != null) { var typeProjector = this.GetEntityExpression(table, entity); var pred = DbExpressionReplacer.Replace(updateCheck.Body, updateCheck.Parameters[0], typeProjector); if (pred != null) { where = where.And(pred); } } var assignments = this.GetColumnAssignments(table, instance, entity, (e, m) => this.mapping.IsUpdatable(e, m)); var update = new DbUpdateCommand(table, where, assignments); if (selector != null) { return(new DbBlockCommand ( update, new DbIFCommand ( this.translator.Linguist.Language.GetRowsAffectedExpression(update).GreaterThan(Expression.Constant(0)), this.GetUpdateResult(entity, instance, selector), exp ) )); } else if (exp != null) { return(new DbBlockCommand ( update, new DbIFCommand ( this.translator.Linguist.Language.GetRowsAffectedExpression(update).LessThanOrEqual(Expression.Constant(0)), exp, null ) )); } else { return(update); } }
protected override Expression VisitUpdate(DbUpdateCommand update) { this.Write("UPDATE "); this.WriteTableName(update.Table.Name); this.WriteLine(Indentation.Same); var saveHide = this.HideColumnAliases; this.HideColumnAliases = true; this.Write("SET "); for (int i = 0, n = update.Assignments.Count; i < n; i++) { var 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); }
protected virtual bool CompareUpdate(DbUpdateCommand x, DbUpdateCommand y) { return(this.Compare(x.Table, y.Table) && this.Compare(x.Where, y.Where) && this.CompareColumnAssignments(x.Assignments, y.Assignments)); }
protected override Expression VisitUpdate(DbUpdateCommand update) { return(this.BuildExecuteCommand(update)); }