我有一个相当大的数据库,其中包含为不同业务模块创建的表.
我们决定分别为不同的模块创建不同的edmx文件.
但是,在尝试为将要写入不同edmx中的多个表的逻辑操作实现TransactionScope时,如何防止使用MSDTC?同样,底层数据库是相同的,我不想在这种情况下使用MSDTC.
有没有办法通过活动事务传递打开的SQL连接?
提前感谢您的帮助.
问候,
威廉
最佳答案 当数据库不同和/或连接字符串不同时,TransactionScope会对MSDTC进行登记.
Rick Strahl有一个great article(他的观点是LINQ to SQL,但它适用于EF).钱款:
TransactionScope is a high level Transaction wrapper that makes it
real easy to wrap any code into a transaction without having to track
transactions manually. Traditionally TransactionScope was a .NET
wrapper around the Distributed Transaction Coordinator (DTC) but it’s
functionality has expanded somewhat. One concern is that the DTC is
rather expensive in terms of resource usage and it requires that the
DTC service is actually running on the machine (yet another service
which is especially bothersome on a client installation).However, recent updates to TransactionScope and the SQL Server Client
drivers make it possible to use TransactionScope class and the ease of
use it provides without requiring DTC as long as you are running
against a single database and with a single consistent connection
string. In the example above, since the transaction works with a
single instance of a DataContext, the transaction actually works
without involving DTC. This is in SQL Server 2008.
另见SO question/answer,我找到了Rick博客的链接.
因此,如果您要连接到同一个数据库并使用相同的连接字符串,则不应涉及DTC.