问题
I am using EF to access Sql azure. In one situation I need to make changes to two databases, for which normally I would use TransactionScope and it would escalate to MSDTC. Now MSDTC is not supported in Sql Azure, so I can't use TransactionScope.
Is there another way to do this? (other than doing it without the distributed transaction and having to manually rollback state somehow).
回答1:
One way to write your code without using the TransactionScope class is to use SqlTransaction. The SqlTransaction class doesn’t use the transaction manager, it wraps the commands within a local transaction that is committed when you call the Commit() method.
I would suggest you looking at Handling Transactions in SQL Azure article.
回答2:
TransactionScope is now supported for Azure SQL DB. See my answer to the following posting: TransactionScope() in Sql Azure. This also applies when you are using EF.
来源:https://stackoverflow.com/questions/11164345/alternative-to-transactionscope-for-entity-framework-when-using-sql-azure-across