C# - System.Transactions.TransactionScope [英] C# - System.Transactions.TransactionScope
问题描述
我很好奇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).
我的问题,是你能放的任意的code在一个TransactionScope的使用块该操作是事务? 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.
如果它可以被用来制造code比数据库连接事务性的其他,这是支持的呢?这似乎疯了我,如果它可以使有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.
下面是事务性内存中的一个例子: <一href="http://www.$c$cproject.com/KB/dotnet/Transactional_Repository.aspx">http://www.$c$cproject.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组件,但它是pretty的容易实现这样的部件 - 最新的操作系统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# - System.Transactions.TransactionScope的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!