public static Message Update(XmlReader xmlReader, DbConnection connection, string operationType, DbCommandBuilder commandBuilder, string action) { string baseSelect = commandBuilder.DataAdapter.SelectCommand.CommandText; var baseCommand = commandBuilder.GetUpdateCommand(); var commandCache = new Dictionary<string, DbCommand>(); int count = 0; while (xmlReader.ReadToFollowing("Pair", AdoNetAdapter.MESSAGENAMESPACE)) { xmlReader.ReadToFollowing("Before", AdoNetAdapter.MESSAGENAMESPACE); var beforeValues = GetParameterValues(xmlReader.ReadSubtree(), baseCommand.Parameters); string beforeColumns = CreateColumnList(commandBuilder, beforeValues.Keys); xmlReader.ReadToFollowing("After", AdoNetAdapter.MESSAGENAMESPACE); var afterValues = GetParameterValues(xmlReader.ReadSubtree(), baseCommand.Parameters); string afterColumns = CreateColumnList(commandBuilder, afterValues.Keys); string columns = string.Format("B:{0}|A:{1}", beforeColumns, afterColumns); DbCommand command = null; if (commandCache.ContainsKey(columns)) command = commandCache[columns]; else { commandBuilder.DataAdapter.SelectCommand.CommandText = baseSelect.Replace("*", columns); commandBuilder.RefreshSchema(); command = commandBuilder.GetUpdateCommand(); commandCache[columns] = command; } DbHelpers.SetSourceParameters(beforeValues, command.Parameters); DbHelpers.SetTargetParameters(afterValues, command.Parameters); count += command.ExecuteNonQuery(); } return DbHelpers.CreateMessage(operationType, count, action); }
public static Message Create(XmlReader xmlReader, DbConnection connection, string operationType, DbCommandBuilder commandBuilder, string action) { int count = 0; string baseSelect = commandBuilder.DataAdapter.SelectCommand.CommandText; var baseCommand = commandBuilder.GetInsertCommand(); var commandCache = new Dictionary<string, DbCommand>(); 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.GetInsertCommand(); commandCache[columns] = command; } DbHelpers.SetTargetParameters(values, command.Parameters); count += command.ExecuteNonQuery(); } return DbHelpers.CreateMessage(operationType, count, action); }