C# - System.Transactions.TransactionScope
- 作者: 磨人的小表砸
- 来源: 51数据库
- 2022-10-20
问题描述
我对 TransactionScope 类很好奇.
I was curious about the TransactionScope class.
在大多数情况下,我认为它是用于数据库连接(这就是我使用它的目的).
For the most part, I assume it was intended for database connections (which is what I've used it for).
我的问题是,您可以将任何代码放在 TransactionScope 的 using 块中以使其具有事务性吗?MS 文档对此并不清楚.
My question, is can you put any code in the using-block of a TransactionScope to make it transactional? MS documentation is not clear on this.
如果它可以用于使数据库连接以外的代码成为事务性的,那么支持哪些?如果它能让 System.IO.File 操作成为事务性的,我觉得这很疯狂.
If it can be used to make code other than database connections transactional, which ones are supported? It would seem crazy to me if it could make System.IO.File operations transactional.
推荐答案
TransactionScope 不仅适用于数据库.每个实现 IEnlistmentNotification 接口的组件都可以参与事务范围的两阶段提交.
TransactionScope is not only for the databases. Every component that implements IEnlistmentNotification interface can participate in two-phase commit of the transaction scope.
以下是事务性内存存储的示例:http://www.codeproject.com/KB/dotnet/Transactional_Repository.aspx
Here is an example of transactional in-memory storage: http://www.codeproject.com/KB/dotnet/Transactional_Repository.aspx
此外,我不确定 .NET 中是否有用于事务文件 IO 的组件,但实现此类组件非常容易 - 最新的操作系统(如 Vista 和 Windows Server 2008)支持事务文件 IO.
Also, I'm not sure if there are components in .NET for transactional file IO, but it is pretty easy to implement such component - latest OS like Vista and Windows Server 2008 have support for transaction file IO.
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
