Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zzzprojects/abd9821e2c2d684bf7582fd941acc7f3 to your computer and use it in GitHub Desktop.
Save zzzprojects/abd9821e2c2d684bf7582fd941acc7f3 to your computer and use it in GitHub Desktop.
// Set Global Configuration
BulkOperationManager.BulkOperationBuilder = operation => operation.BatchSize = 1000;
// Set Instance Configuration
context.BulkSaveChanges(operation => operation.BatchSize = 100);
context.BulkSaveChanges(operation =>
{
// Increasing/Decreasing the value affects the performance
// There is no perfect value, it depends on column, trigger, index, etc.
operation.BatchSize = 100; // Default value = 10,000 for SQL Server
// Specify the timeout for a batch
operation.BatchTimeout = 180; // seconds, default value = 15s
// Specify the delay between batch executions
operation.BatchDelayInterval = 100; // milliseconds, default value = 0
});
context.BulkSaveChanges(operation =>
{
// Specify how many batch a temporary table must contain
bulk.TemporaryTableBatchByTable = 5; // Default value = 0 (infinite)
// Can increase/decrease performance depending on the number of columns
bulk.TemporaryTableInsertBatchSize = 1000; // Default value = 10,000
// Increasing the value may improve performance for sources with few records
bulk.TemporaryTableMinRecord = 15; // Default value = 10
// Using TableLock may increase performance but also increase row lock
bulk.TemporaryTableUseTableLock = true; // Default value = false
});
context.BulkSaveChanges(operation =>
{
// SET default options to use when a SqlBulkCopy instance is used
bulk.SqlBulkCopyOptions = SqlBulkCopyOptions.Default | SqlBulkCopyOptions.TableLock;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment