Entity Framework Plus Batch Operations
Batch Delete
Deletes multiples rows in a single database roundtrip and without loading entities in the context.
// using Z.EntityFramework.Plus; // Don't forget to include this. // DELETE all users inactive for 2 years var date = DateTime.Now.AddYears(-2); ctx.Users.Where(x => x.LastLoginDate < date) .Delete(); // DELETE using a BatchSize var date = DateTime.Now.AddYears(-2); ctx.Users.Where(x => x.LastLoginDate < date) .Delete(x => x.BatchSize = 1000);
Support: EF5, EF6, EF Core
Batch Update
Updates multiples rows using an expression in a single database roundtrip and without loading entities in the context.
// using Z.EntityFramework.Plus; // Don't forget to include this. // UPDATE all users inactive for 2 years var date = DateTime.Now.AddYears(-2); ctx.Users.Where(x => x.LastLoginDate < date) .Update(x => new User() { IsSoftDeleted = 1 });
Support: EF5, EF6, EF Core