我一直想尝试使用TransactionScope
,但我就是无法弄清楚人们认为它有什么用处。所以让我们举个例子:
using(TransactionScope tran = new TransactionScope()) {
CallAMethodThatDoesSomeWork1();
CallAMethodThatDoesSomeWork2();
tran.Complete();
}
因此,最基本的问题是:我该如何编写 "CallAMethodThatDoesSomeWork1()
",以便在让 "CallAMethodThatDoesSomeWork2()
" 抛出异常时,它知道如何回滚其操作?