public void EF6_Delete_Single_SaveChanges(object sender, bool showResult) { My.Database.Reset(My.AppSettings.NbTestItems, false, false); var affectedRows = 0; var clock = new Stopwatch(); List <EntitiesContextEF6.Invoice> list; using (var context = new EntitiesContextEF6()) { list = context.Invoices.ToList(); } clock.Start(); for (var i = 0; i < My.AppSettings.NbTestItems; i++) { using (var context = new EntitiesContextEF6()) { context.Invoices.Attach(list[i]); context.Invoices.Remove(list[i]); affectedRows += context.SaveChanges(); } } clock.Stop(); if (showResult) { My.Result.Show(this, sender, clock, affectedRows); } }
private void EF6_Delete_Many_SaveChanges_Bad(object sender, bool showResult) { My.Database.Reset(My.AppSettings.NbTestItems, false, false); var clock = new Stopwatch(); var affectedRows = 0; using (var context = new EntitiesContextEF6()) { var list = context.Invoices.Take(My.AppSettings.NbTestItems).ToList(); clock.Start(); for (int i = 0; i < My.AppSettings.NbTestItems; i++) { context.Invoices.Remove(list[i]); affectedRows += context.SaveChanges(); } clock.Stop(); } if (showResult) { My.Result.Show(this, sender, clock, My.AppSettings.NbTestItems); } }
private void EF6_Delete_Many_SaveChanges_Good(object sender, bool showResult) { My.Database.Reset(My.AppSettings.NbTestItems, false, false); var clock = new Stopwatch(); var affectedRows = 0; using (var context = new EntitiesContextEF6()) { context.Invoices.RemoveRange(context.Invoices.Take(My.AppSettings.NbTestItems)); clock.Start(); affectedRows = context.SaveChanges(); clock.Stop(); } if (showResult) { My.Result.Show(this, sender, clock, My.AppSettings.NbTestItems); } }