Alternative to TransactionScope for Entity Framework when using Sql Azure across multiple connections

ぃ、小莉子 提交于 2020-01-02 05:22:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!