System.Data.Common.DbCommand CreateDeleteCommand() { if (_commandBuilder == null) { CreateDataAdapter(); } return(_commandBuilder.GetDeleteCommand(true)); }
public static Message Delete(XmlReader xmlReader, DbConnection connection, string operationType, DbCommandBuilder commandBuilder, string action) { string baseSelect = commandBuilder.DataAdapter.SelectCommand.CommandText; var baseCommand = commandBuilder.GetDeleteCommand(); var commandCache = new Dictionary<string, DbCommand>(); int count = 0; while (xmlReader.ReadToFollowing("Row", AdoNetAdapter.MESSAGENAMESPACE)) { var values = GetParameterValues(xmlReader.ReadSubtree(), baseCommand.Parameters); string columns = CreateColumnList(commandBuilder, values.Keys); DbCommand command = null; if (commandCache.ContainsKey(columns)) command = commandCache[columns]; else { commandBuilder.DataAdapter.SelectCommand.CommandText = baseSelect.Replace("*", columns); commandBuilder.RefreshSchema(); command = commandBuilder.GetDeleteCommand(); commandCache[columns] = command; } DbHelpers.SetSourceParameters(values, command.Parameters); count += command.ExecuteNonQuery(); } return DbHelpers.CreateMessage(operationType, count, action); }