public override void Delete(SqlDeleteExpression deleteExpression) { var formatResult = this.SqlDatabaseContext.SqlQueryFormatterManager.Format(deleteExpression, SqlQueryFormatterOptions.Default); using (var command = this.CreateCommand()) { command.CommandText = formatResult.CommandText; foreach (var value in formatResult.ParameterValues) { this.AddParameter(command, value.Type, value.Value); } Logger.Info(() => this.FormatCommand(command)); try { var count = command.ExecuteNonQueryEx(this.DataAccessModel); } catch (Exception e) { var decoratedException = this.LogAndDecorateException(e, command); if (decoratedException != null) { throw decoratedException; } throw; } } }
public override void Delete(SqlDeleteExpression deleteExpression) { var formatResult = this.SqlDatabaseContext.SqlQueryFormatterManager.Format(deleteExpression, SqlQueryFormatterOptions.Default); using (var command = this.CreateCommand()) { command.CommandText = formatResult.CommandText; foreach (var value in formatResult.ParameterValues) { this.AddParameter(command, value.Item1, value.Item2); } Logger.Debug(() => this.FormatCommand(command)); try { command.ExecuteNonQuery(); } catch (Exception e) { var relatedSql = this.SqlDatabaseContext.GetRelatedSql(e) ?? this.FormatCommand(command); var decoratedException = this.SqlDatabaseContext.DecorateException(e, null, relatedSql); Logger.ErrorFormat(e.ToString()); if (decoratedException != e) { throw decoratedException; } throw; } } }
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 VisitDelete(SqlDeleteExpression deleteExpression) { var where = this.Visit(deleteExpression.Where); if (deleteExpression.Where != where) { return(new SqlDeleteExpression(deleteExpression.Table, deleteExpression.Alias, where)); } return(deleteExpression); }
protected virtual Expression VisitDelete(SqlDeleteExpression deleteExpression) { var source = this.Visit(deleteExpression.Source); var where = this.Visit(deleteExpression.Where); if (deleteExpression.Source != source || deleteExpression.Where != where) { return(new SqlDeleteExpression(source, where)); } return(deleteExpression); }
protected override Expression VisitDelete(SqlDeleteExpression deleteExpression) { this.Write("DELETE "); this.Write("FROM "); this.Visit(deleteExpression.Table); this.WriteLine(); this.Write(" WHERE "); this.WriteLine(); this.ignoreAlias = deleteExpression.Alias; this.replaceAlias = deleteExpression.Table.Name; this.Visit(deleteExpression.Where); this.ignoreAlias = ""; return(deleteExpression); }
protected override Expression VisitDelete(SqlDeleteExpression deleteExpression) { if (!(deleteExpression.Source is SqlProjectionExpression projection)) { return(deleteExpression); } 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 SqlDeleteExpression(table, where)); }
public abstract Task DeleteAsync(SqlDeleteExpression deleteExpression, CancellationToken cancellationToken);
public abstract Task DeleteAsync(SqlDeleteExpression deleteExpression);
public abstract void Delete(SqlDeleteExpression deleteExpression);
protected override Expression VisitDelete(SqlDeleteExpression deleteExpression) { return(deleteExpression); }