This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (var ctx = new CurrentContext()) | |
{ | |
var lastLogin = DateTime.Now.AddYears(-2); | |
var list = ctx.Customers.Where(x => x.LastLogin < lastLogin).ToList(); | |
ctx.Customers.RemoveRange(list); | |
// HOW to automatically handle soft delete? | |
ctx.BulkSaveChanges(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Single Key | |
ctx.BulkUpdate(customers, operation => operation.ColumnPrimaryKeyExpression = | |
customer => customer.Code); | |
// Surrogate Key (with anonymous type) | |
ctx.BulkUpdate(customers, operation => operation.ColumnPrimaryKeyExpression = | |
customer => new { customer.Code1, customer.Code2, customer.Code3 }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// DON'T add the key if auto-generated | |
ctx.BulkInsert(customers, operation => operation.ColumnInputExpression = | |
customer => new {customer.Name, customer.Email}); | |
// ALWAYS add the key | |
ctx.BulkUpdate(customers, operation => operation.ColumnInputExpression = | |
customer => new { customer.ID, customer.Name, customer.Email }); | |
// ALWAYS add the key | |
ctx.BulkMerge(customers, operation => operation.ColumnInputExpression = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EntityFrameworkManager.DefaultEntityFrameworkPropagationValue = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Benchmark() | |
{ | |
// BENCHMARK using Stopwatch | |
var clock1 = new Stopwatch(); | |
var clock2 = new Stopwatch(); | |
var nbRecord = 1000; | |
var nbTry = 5; | |
var list = GenerateData(nbRecord); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context.BulkSaveChanges(operation => | |
{ | |
bulk.SqlBulkCopyOptions = SqlBulkCopyOptions.Default | SqlBulkCopyOptions.TableLock; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (var ctx = new EntitiesContext()) | |
{ | |
ctx.BulkSaveChanges(operation => | |
{ | |
operation.RetryCount = 3; | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context.BulkSaveChanges(operation => | |
{ | |
bulk.TemporaryTableBatchByTable = 5; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
StringBuilder logger = new StringBuilder(); | |
using (var ctx = new EntitiesContext()) | |
{ | |
ctx.BulkSaveChanges(operation => | |
{ | |
operation.Log += s => logger.AppendLine(s); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (var ctx = new EntitiesContext()) | |
{ | |
ctx.BulkSaveChanges(operation => | |
{ | |
operation.BulkOperationExecuting = bulkOperation => { /* configuration */ }; | |
}); | |
} |