自定义交易范围
TransactionScope 有几个限制: 1. IsolationLevel在事务期间不能改变 2. 嵌套事务范围并不是我们所知道的真正的嵌套事务
是否可以编写自定义 TransactionScope 来解决这些限制,或者它们是否已集成到 System.Transactions 的核心中并且无法更改?
更新。如果不是,为什么人们要创建自定义 TransactionScope?它可以解决什么问题?
TransactionScope has several restrictions:
1. IsolationLevel can't change during transaction
2. Nested transaction scopes are not really what we know as nested transactions
Is it possible to write custom TransactionScope to workaround these restrictions or are they integrated into core of System.Transactions and can't be changed?
Upd. If not why do people create custom TransactionScopes? What problems does it allow to solve?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于你的第二点(并阅读评论);事实上,“一旦失败,一切立即回滚”是 DTC 的固有部分;整个外部事务是原子单元。您可能能够在DTC事务内部使用一些常规的SQL事务,但说实话,这让事情变得复杂......
我的建议:
,我更喜欢第一个,因为回滚的成本很高(提交很便宜)。
(我不确定你的第一点,但我相信这很像石头)
Re your 2nd point (and reading the comment); indeed, the "one fail, everything rolls back immediately" is an inherent part of DTC; the entire outer transaction is the atomic unit. You might be able to use some regular SQL transactions inside the DTC transaction, but to be honest that is making things complex...
My suggestion:
and I prefer the first, as rollback is expensive (commit is cheap).
(I don't know definitively for your first point, but I believe that is pretty stone-like)