TransactionScope Complete()在退出USING语句之前不提交事务
我遇到这种奇怪的行为,只有在using
退出时才提交事务,而不是在调用scope.Complete();
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew)) { scope.Complete(); // data still doesn't show in db } // now shows in db
如何在退出using
语句之前提交事务?
从文件 :
如果TransactionScope对象创建了事务,则资源管理器之间的实际提交工作发生在End Using语句中。
因此,看起来你可以在using语句结束之前真正提交事务。