public void TestMethod1() { var scopeFactory = new ContextExtension("bak"); using (var scope = scopeFactory.GetContextScope()) { var db = scopeFactory.GetDbContext <CommonDbContext>(); using (var dbContextScope = scopeFactory.GetContextScope()) { db.Users.Add(new User() { Id = Guid.NewGuid(), Name = "Marshall1", Email = "[email protected]", WelcomeEmailSent = false, CreatedOn = DateTime.UtcNow }); dbContextScope.SaveChanges(); } using (var dbContextScope = scopeFactory.GetContextScope()) { db.Users.FirstOrDefault().Name = "bababab1"; dbContextScope.SaveChanges(); } using (var dbContextScope = scopeFactory.GetContextScope()) { db.Users.FirstOrDefault().Email = "dddd1"; dbContextScope.SaveChanges(); } scope.SaveChanges(); } }
public void TestMethod2() { var scopeFactory = new ContextExtension("demo"); using (var scope = scopeFactory.GetContextScope()) { var db = scopeFactory.GetDbContext <CommonDbContext>(); db.Users.Add(new User() { Id = Guid.NewGuid(), Name = "Marshall1", Email = "[email protected]", WelcomeEmailSent = false, CreatedOn = DateTime.UtcNow }); scope.SaveChanges(); } }