在 .Net 中,我可以指定默认的应用程序范围隔离级别吗?
当我使用 TransactionScope
对象时,我可以指定隔离级别 使用事务选项。
如果未指定,则使用的默认隔离级别是什么?
是否可以设置 TransactionScope 使用的应用程序范围的默认隔离级别?
When I am using a TransactionScope
object I can specify the Isoaltion Level using the transaction options.
What is the default isolation level used if none is specified?
Is it possible to set an application wide default isolation level that would be used by the TransactionScope
s?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建自己的对象来包装 TransactionScope,设置正确的隔离级别,然后使用它代替 TransactionScope。
我不能保证这会起作用,但听起来似乎有道理。 如果确实如此,请告诉我,我会更新答案。
You could create your own object to wrap the TransactionScope, setting the correct Isolation level, then use that in place of a TransactionScope.
I can't guarantee this would work, but sounds plausible. Let me know if it does and I'll update the answer.
我们只有一个辅助方法
TransactionManager.CreateTransactionScope
,它使用项目范围的选项创建一个。 它也是封装其他逻辑的有用位置,例如,如果存在环境事务,您可以使用它,或者创建具有兼容选项的嵌套事务,或者创建一个新事务,具体取决于适合您的应用程序的事务(您可能想要创建重载指定允许哪些行为)。We just have a helper method
TransactionManager.CreateTransactionScope
which creates one with the project-wide options. It's also a useful place to encapsulate additional logic such as if there is an ambient transaction you can either use that, or create a nested transaction with compatible options, or create a new transaction, depending on what suits your application (you may want to create overloads specifying which of these behaviours are allowed).