在多个连接中使用Sql Azure时,替代TransactionScope for Entity Framework [英] Alternative to TransactionScope for Entity Framework when using Sql Azure across multiple connections

查看:117
本文介绍了在多个连接中使用Sql Azure时,替代TransactionScope for Entity Framework的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用EF来访问Sql的天蓝色。在一种情况下,我需要更改两个数据库,通常我会使用TransactionScope,它将升级到MSDTC。现在,Sql Azure不支持MSDTC,所以我不能使用TransactionScope。



有另一种方法吗? (除了没有分布式事务而不需要手动回滚状态)。

解决方案

使用 TransactionScope 类是使用 SqlTransaction 。 SqlTransaction类不使用事务管理器,它将命令包装在调用Commit()方法时提交的本地事务中。



我会建议你请参阅处理SQL Azure中的事务文章。


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).

解决方案

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.

这篇关于在多个连接中使用Sql Azure时,替代TransactionScope for Entity Framework的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆