private void ExecuteBatchMultipleCommands(DbBatch batch) { //Note: for multiple commands, we cannot include trans statements into batch commands, like add 'Begin Trans' to the first command // and 'Commit' to the last command - this will fail. We start/commit trans using separate calls // Also, we have to manage connection explicitly, to start/commit transaction var conn = batch.UpdateSet.Connection; try { var inNewTrans = conn.DbTransaction == null; if (inNewTrans) { conn.BeginTransaction(commitOnSave: true); } foreach (var cmd in batch.Commands) { ExecuteBatchCommand(cmd, conn); }//foreach if (inNewTrans) { conn.Commit(); } ReleaseConnection(conn); } catch { ReleaseConnection(conn, inError: true); throw; } }
private void ExecuteBatchSingleCommand(DbBatch batch) { var conn = batch.UpdateSet.Connection; try { var cmd = batch.Commands[0]; ExecuteBatchCommand(cmd, conn); ReleaseConnection(conn); } catch { ReleaseConnection(conn, inError: true); throw; } }
public DbBatch Build(DbUpdateSet updateSet) { _batch = new DbBatch() { UpdateSet = updateSet }; _commandBuilder = new DataCommandBuilder(_driver, batchMode: true, mode: SqlGenMode.PreferLiteral); AddScheduledCommands(updateSet.Session.ScheduledCommandsAtStart); foreach (var group in updateSet.UpdateGroups) { foreach (var tableGroup in group.TableGroups) { AddUpdateGroup(tableGroup); }// foreach group } AddScheduledCommands(updateSet.Session.ScheduledCommandsAtEnd); FinalizeCurrentCommand(completed: true); return(_batch); }