public long CallSaveChangesOnceInTransaction() { _timer.Restart(); try { using (var dbContext = new ApplicationDbContext()) { using (var transactionScope = dbContext.Database.BeginTransaction()) { for (var i = 0; i < _iterations; i++) { dbContext.Products.Add(new Product(Guid.NewGuid())); } dbContext.SaveChanges(); transactionScope.Commit(); } } } catch (Exception ex) { throw ex; } return _timer.ElapsedMilliseconds; }
public long BulkInsert() { _timer.Restart(); using (var dbContext = new ApplicationDbContext()) { var products = new List<Product>(); using (var transactionScope = dbContext.Database.BeginTransaction()) { for (var i = 0; i < _iterations; i++) { products.Add(new Product(Guid.NewGuid())); } dbContext.BulkInsert(products); dbContext.SaveChanges(); transactionScope.Commit(); } } return _timer.ElapsedMilliseconds; }
public long CallSaveChangesOnceUsingAddRange() { _timer.Restart(); using (var dbContext = new ApplicationDbContext()) { var products = new List<Product>(); for (var i = 0; i < _iterations; i++) { products.Add(new Product(Guid.NewGuid())); } dbContext.Products.AddRange(products); dbContext.SaveChanges(); } return _timer.ElapsedMilliseconds; }
public long WarmingUp() { _timer.Restart(); using (var dbContext = new ApplicationDbContext()) { dbContext.Products.Add(new Product(Guid.NewGuid())); dbContext.SaveChanges(); } return _timer.ElapsedMilliseconds; }
public long CallSaveChangesRepeatedly() { _timer.Restart(); using (var dbContext = new ApplicationDbContext()) { for (var i = 0; i < _iterations; i++) { dbContext.Products.Add(new Product(Guid.NewGuid())); dbContext.SaveChanges(); } } return _timer.ElapsedMilliseconds; }