Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
585 views
in Technique[技术] by (71.8m points)

c# - Will an inner transaction scope roll back if the outer transaction scope doesn't complete?

I have two transaction scopes, one within another. I would love to know if the inner transaction scope will be rolled back after it has been committed and the outer one does not complete.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It depends on the scope option you start the nested transaction scope with.

If you use the default option TransactionScopeOption.Required then the nested scope will enlist in the same transaction as the outer scope and as such when the outer scope rolls back the inner scope will also be rolled back even if it has called Complete.

If, however, you use TransactionScopeOption.RequiresNew then the nested scope will begin its own transaction and complete it separately from the outer scope, so it will not roll back even if the outer scope rolls back.

If you use TransactionScopeOption.Suppress then the nested scope will not take part in the outer transaction and will complete non-transactionally, thus does not form part of the work that would be rolled back if the outer transaction rolls back.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...