public void SubmitOrder() { int p = 1; using (CocurrentDBEntities db = new CocurrentDBEntities()) { var log = db.InventoryLog; var inventory = db.Inventory; using (var transaction = db.Database.BeginTransaction()) { var inventory_model = inventory.FirstOrDefault(a => a.ProductId == p); inventory_model.ProductCount = inventory_model.ProductCount - 1; int stat = db.SaveChanges(); InventoryLog logmodel = new InventoryLog() { Title = "logged,see coccurence happening" }; log.Add(logmodel); db.SaveChanges(); Thread.Sleep(500); transaction.Commit(); } } //using() //using(Co) }
private bool LockForProcedure(int proId) { using (CocurrentDBEntities db = new CocurrentDBEntities()) { SqlParameter[] parameters = { new SqlParameter("@ProductId", SqlDbType.Int), new SqlParameter("@IsSuccess", SqlDbType.Bit) }; parameters[0].Value = proId; parameters[1].Direction = ParameterDirection.Output; var data = db.Database.ExecuteSqlCommand("exec LockProc @ProductId,@IsSuccess output", parameters); string n2 = parameters[1].Value.ToString(); return(n2 == "True"); } }