Skip to content

Instantly share code, notes, and snippets.

View JonathanMagnan's full-sized avatar

Jonathan Magnan JonathanMagnan

View GitHub Profile
var ctx = new EntitiesContext();
// Easy to use
ctx.BulkMerge(list);
// Easy to customize
context.BulkDelete(customers,
bulk => bulk.ColumnPrimaryKeyExpression = customer => customer.Code; });
// UPDATE all customers that are inactive for more than two years
context.Customers
.Where(x => x.Actif && x.LastLogin < DateTime.Now.AddYears(-2))
.UpdateFromQuery(x => new Customer {Actif = false});
// DELETE all customers that are inactive for more than two years
context.Customers
.Where(x => x.LastLogin < DateTime.Now.AddYears(-2))
.DeleteFromQuery();
List<AuditEntry> auditEntries = new List<AuditEntry>();
using (var ctx = new EntitiesContext())
{
ctx.BulkSaveChanges(list, operation =>
{
operation.UseAudit = true;
operation.BulkOperationExecuted = bulkOperation => auditEntries.AddRange(bulkOperation.AuditEntries);
});
}
using (var ctx = new EntitiesContext())
{
ctx.BulkSaveChanges(operation =>
{
operation.BulkOperationExecuting = bulkOperation => { /* configuration */ };
});
}
StringBuilder logger = new StringBuilder();
using (var ctx = new EntitiesContext())
{
ctx.BulkSaveChanges(operation =>
{
operation.Log += s => logger.AppendLine(s);
});
}
using (var ctx = new EntitiesContext())
{
ctx.BulkSaveChanges(operation =>
{
operation.RetryCount = 3;
});
}
context.BulkSaveChanges(operation =>
{
bulk.SqlBulkCopyOptions = SqlBulkCopyOptions.Default | SqlBulkCopyOptions.TableLock;
});