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 "";