1.在控制器里引用using System.Transactions;

2.在你需要事务回滚的地方外面套一层using (TransactionScope sc = new TransactionScope()){}

using (TransactionScope sc = new TransactionScope())
            {
                try
                {
                    using (wcfDemoEntities db = new wcfDemoEntities())
                    {
                        user user2 = new user() {  UserName = name, PassWord = "1212",Discribe="fdsf",SubmitTime=DateTime.Now };
                        db.user.Add(user2);
                        db.SaveChanges();
                    }
                    sc.Complete();//放在catch上面,否则不能回滚
                }
                catch (Exception)
                {
                }
            }
            return "";

 

相关文章:

  • 2021-09-16
  • 2021-12-26
  • 2021-12-02
  • 2021-10-28
  • 2022-12-23
猜你喜欢
  • 2021-10-02
  • 2021-05-27
  • 2022-01-07
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
相关资源
相似解决方案