/// <summary> /// Efficiently inserts multiple rows, in batches as necessary. /// </summary> public static async Task <int> BulkInsertAsync(this DbConnectorCommand command, IEnumerable <DbParameters> rows, BulkInsertSettings?settings = null, CancellationToken cancellationToken = default) { var rowCount = 0; foreach (var(sql, parameters) in GetBulkInsertCommands(command.Text, command.Parameters, rows, settings)) { rowCount += await CreateBatchCommand(command, sql, parameters).ExecuteAsync(cancellationToken).ConfigureAwait(false); } return(rowCount); }
/// <summary> /// Efficiently inserts multiple rows, in batches as necessary. /// </summary> public static int BulkInsert(this DbConnectorCommand command, IEnumerable <DbParameters> rows, BulkInsertSettings?settings = null) { var rowCount = 0; foreach (var(sql, parameters) in GetBulkInsertCommands(command.Text, command.Parameters, rows, settings)) { rowCount += CreateBatchCommand(command, sql, parameters).Execute(); } return(rowCount); }
private static DbConnectorCommand CreateBatchCommand(DbConnectorCommand command, string sql, DbParameters parameters) { var batchCommand = command.Connector.Command(sql, parameters); if (command.IsCached) { batchCommand = batchCommand.Cache(); } if (command.IsPrepared) { batchCommand = batchCommand.Prepare(); } if (command.Timeout != null) { batchCommand = batchCommand.WithTimeout(command.Timeout.Value); } return(batchCommand); }
/// <summary> /// Efficiently inserts multiple rows, in batches as necessary. /// </summary> public static Task <int> BulkInsertAsync(this DbConnectorCommand command, IEnumerable <DbParameters> rows, CancellationToken cancellationToken) => command.BulkInsertAsync(rows, null, cancellationToken);