public void EditProducts1() { try { using (var dbContext = new TwTransactionTest()) { using (var transaction = dbContext.Database.BeginTransaction()) //using (var transaction = dbContext.Database.BeginTransaction(System.Data.IsolationLevel.RepeatableRead)) // using (var transaction = dbContext.Database.BeginTransaction(System.Data.IsolationLevel.Serializable)) { try { var Product = dbContext.Product.FirstOrDefault(p => p.Id == 2); Product.Name = "123"; dbContext.SaveChanges(); Product.Name = "1234"; dbContext.SaveChanges(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); } } } } catch (Exception ex) { throw ex; } }
public static void CreateOrders() { try { using (var dbContext = new TwTransactionTest()) { //using (var con = dbContext.Database.BeginTransaction()) { var order = new Order() { OrderGuid = Guid.NewGuid(), Deleted = false, CreateTime = DateTime.Now, UpdateTime = DateTime.Now }; dbContext.Order.Add(order); //dbContext.SaveChanges(); //dbContext.OrderPost.Add(new OrderPost() //{ // OrderId = order.Id, // CreateTime = DateTime.Now, // UpdateTime = DateTime.Now, // CreateId = i, // UpdateId = j, //}); //Random randomOrderItem = new Random(1); //var orderItemCount = randomOrderItem.Next(20); //for (int m = 1; m <= orderItemCount; m++) //{ // Random random = new Random(1); // var index = random.Next(1459000); // dbContext.OrderItem.Add(new OrderItem() // { // OrderId = order.Id, // OrderItemGuid = Guid.NewGuid(), // ProductId = index, // ProductName = "Name_" + "0" + index // }); //} dbContext.SaveChanges(); //con.Commit(); } } } catch (Exception ex) { throw ex; } }
public static void CreateProducts() { using (var dbContext = new TwTransactionTest()) { dbContext.Product.Add(new Product() { Deleted = false, Name = "Name_", CreateTime = DateTime.Now, UpdateTime = DateTime.Now, }); dbContext.SaveChanges(); } }
public static void EditProducts1() { try { using (var dbContext = new TwTransactionTest()) { //using (var transaction = dbContext.Database.BeginTransaction()) using (var transaction = dbContext.Database.BeginTransaction(System.Data.IsolationLevel.RepeatableRead)) { var Product = dbContext.Product.FirstOrDefault(p => p.Id == 2); Product.Name = "123"; //Thread.Sleep(1000000000); dbContext.SaveChanges(); transaction.Commit(); } } } catch (Exception ex) { throw ex; } }
public static void EditProducts2() { try { using (var dbContext = new TwTransactionTest()) { using (var transaction = dbContext.Database.BeginTransaction()) { var Product = dbContext.Product.FirstOrDefault(p => p.Id == 2); Product.Name = "123456"; dbContext.SaveChanges(); transaction.Commit(); } } } catch (Exception ex) { throw ex; } }