.NET Bulk Operations Batch

Batch Options

BatchSize

Allow you to set the number of records to use in a batch.

For example, if you insert 1000 entities, and you set a batch size of 100, then ten inserts will be performed.

Example

using (var bulk = new BulkOperation(connection))
{
    // easy to use
    bulk.DestinationTableName = "Customers";
    bulk.BatchSize = 100;
    bulk.BulkInsert(dtCustomers);
}

Try it: .NET Core | .NET Framework

BatchTimeout

Allow you to set the maximum of time elapsed for a batch before the command throws a timeout exception.

Example

using (var bulk = new BulkOperation(connection))
{
    // easy to use
    bulk.DestinationTableName = "Customers";
    bulk.BatchTimeout = 180;
    bulk.BulkInsert(dtCustomers);
}

Try it: .NET Core | .NET Framework

BatchDelayInterval

Allow you to set a delay between every batch.

Example

using (var bulk = new BulkOperation(connection))
{
    // easy to use
    bulk.DestinationTableName = "Customers";
    bulk.BatchDelayInterval = 100;
    bulk.BulkInsert(dtCustomers);
}

WARNING: Be careful, this options can often cause lock/deadlock within a transaction.

Try it: .NET Core | .NET Framework

Contents