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 JonathanMagnan/68629fd212dbd0dce1cd3f673458334d to your computer and use it in GitHub Desktop.
Save JonathanMagnan/68629fd212dbd0dce1cd3f673458334d to your computer and use it in GitHub Desktop.
var ctx = new EntitiesContext();
ctx.Customers.AddRange(listToAdd); // add
ctx.Customers.RemoveRange(listToRemove); // remove
listToModify.ForEach(x => x.DateModified = DateTime.Now); // modify
// Easy to use
ctx.BulkSaveChanges();
// Easy to customize
context.BulkSaveChanges(bulk => bulk.BatchSize = 100);
var ctx = new EntitiesContext();
// Easy to use
ctx.BulkInsert(list);
ctx.BulkUpdate(list);
ctx.BulkDelete(list);
ctx.BulkMerge(list);
// Easy to customize
context.BulkMerge(customers,
bulk => bulk.ColumnPrimaryKeyExpression = customer => customer.Code; });
// DELETE all customers that are inactive for more than two years
context.Customers
.Where(x => x.LastLogin < DateTime.Now.AddYears(-2))
.DeleteFromQuery();
// 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});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment