protected override Expression VisitUpdate(SqlUpdateExpression expression) { try { var newSource = this.Visit(expression.Source); this.inUpdate = true; updateTableName = (expression.Source as SqlTableExpression).Name; var newWhere = this.Visit(expression.Where); var newAssignments = this.VisitExpressionList(expression.Assignments); if (newSource != expression.Source || newWhere != expression.Where || newAssignments != expression.Assignments) { return new SqlUpdateExpression(newSource, newAssignments, newWhere); } return expression; } finally { this.inUpdate = false; } }
protected override Expression VisitUpdate(SqlUpdateExpression expression) { if (!expression.RequiresIdentityInsert) { return base.VisitUpdate(expression); } var tableName = ((SqlTableExpression)expression.Source).Name; var typeDescriptor = this .typeDescriptorProvider .GetTypeDescriptors() .Single(c => c.PersistedName == tableName); var insertedColumns = expression .Assignments .OfType<SqlAssignExpression>() .Select(c => new { name = ((SqlColumnExpression)c.Target).Name, value = c.Value, propertyDescriptor = typeDescriptor.GetPropertyDescriptorByColumnName(((SqlColumnExpression)c.Target).Name) }) .ToList(); var columnInfos = QueryBinder .GetColumnInfos(this.typeDescriptorProvider, typeDescriptor.PersistedProperties.Where(c => insertedColumns.All(d => d.propertyDescriptor != c))) .ToList(); var visitedUpdated = (SqlUpdateExpression)base.VisitUpdate(expression); var selectIntoExpression = new SqlSelectExpression ( typeof(void), null, columnInfos.Select ( c => new SqlColumnDeclaration ( null, new SqlColumnExpression(c.DefinitionProperty.PropertyType, null, c.GetColumnName()) ) ) .Concat(insertedColumns.Select(d => d.value.Type.GetUnwrappedNullableType() == typeof(bool) ? new SqlColumnDeclaration(d.name, new BitBooleanExpression(d.value)) : new SqlColumnDeclaration(d.name, d.value))) .ToReadOnlyCollection(), visitedUpdated.Source, visitedUpdated.Where, null, null, false, null, null, false, false, new SqlTableExpression("#TEMP") ); var selectExpression = new SqlSelectExpression(typeof(void), null, null, selectIntoExpression.Into, null, null); var insertExpression = new SqlInsertIntoExpression(visitedUpdated.Source, columnInfos.Select(c => c.GetColumnName()).Concat(insertedColumns.Select(c => c.name)).ToReadOnlyCollection(), null, selectExpression, null, true); var deleteExpression = new SqlDeleteExpression(visitedUpdated.Source, visitedUpdated.Where); var list = new List<Expression> { selectIntoExpression, deleteExpression, new SqlSetCommandExpression("IDENTITY_INSERT", visitedUpdated.Source, new SqlKeywordExpression("ON")), insertExpression, new SqlSetCommandExpression("IDENTITY_INSERT", visitedUpdated.Source, new SqlKeywordExpression("OFF")), }; return new SqlStatementListExpression(list); }
protected virtual Expression VisitUpdate(SqlUpdateExpression expression) { var newWhere = this.Visit(expression.Where); var newAssignments = this.VisitExpressionList(expression.Assignments); if (newWhere != expression.Where || newAssignments != expression.Assignments) { return(new SqlUpdateExpression(expression.Table, newAssignments, newWhere)); } return(expression); }
protected override Expression VisitUpdate(SqlUpdateExpression updateExpression) { var projection = updateExpression.Source as SqlProjectionExpression; if (projection == null) { return updateExpression; } if (projection.Select.From.NodeType != (ExpressionType)SqlExpressionType.Table) { throw new NotSupportedException(); } var table = (SqlTableExpression)projection.Select.From; var alias = table.Alias; var where = AliasReferenceReplacer.Replace(projection.Select.Where, alias, table.Name); return new SqlUpdateExpression(table, updateExpression.Assignments, where); }
protected override Expression VisitUpdate(SqlUpdateExpression expression) { this.hashCode ^= expression.RequiresIdentityInsert ? 2044950846 : 0; return(base.VisitUpdate(expression)); }
protected override Expression VisitUpdate(SqlUpdateExpression expression) { this.hashCode ^= expression.RequiresIdentityInsert ? 2044950846 : 0; return base.VisitUpdate(expression); }
protected override Expression VisitUpdate(SqlUpdateExpression expression) { SqlUpdateExpression current; if (!TryGetCurrent(expression, out current)) { return expression; } if (!(this.result &= current.RequiresIdentityInsert == expression.RequiresIdentityInsert)) { return expression; } if (!(this.result &= current.NodeType == expression.NodeType)) { return expression; } if (!(this.result &= current.Type == expression.Type)) { return expression; } this.currentObject = current.Source; this.Visit(expression.Source); if (!this.result) { return expression; } this.currentObject = current.Where; this.Visit(expression.Where); if (!this.result) { return expression; } this.currentObject = current.Assignments; this.VisitExpressionList(expression.Assignments); if (!this.result) { return expression; } this.currentObject = current; return expression; }
protected override Expression VisitUpdate(SqlUpdateExpression expression) { this.Write("UPDATE "); this.Visit(expression.Table); this.Write(" SET "); this.WriteDeliminatedListOfItems(expression.Assignments, c => this.Visit(c)); if (expression.Where == null) { this.Write(";"); } this.Write(" WHERE "); this.Visit(expression.Where); this.Write(";"); return expression; }
protected virtual Expression VisitUpdate(SqlUpdateExpression expression) { var newSource = this.Visit(expression.Source); var newWhere = this.Visit(expression.Where); var newAssignments = this.VisitExpressionList(expression.Assignments); if (newSource != expression.Source || newWhere != expression.Where || newAssignments != expression.Assignments) { return new SqlUpdateExpression(newSource, newAssignments, newWhere); } return expression; }
protected override Expression VisitUpdate(SqlUpdateExpression updateExpression) { return updateExpression; }