我应该在共享托管服务器中使用transacion范围吗?

时间:2013-04-20 07:30:53

标签: asp.net entity-framework transactionscope

假设我必须使用不同的方法,并将它们放在transaction scope中。 但每种方法都打开它的连接。所以我需要在Windows服务器中启用MSDTC service。 但它是一个共享的托管服务器,我无法启用它。

class Debit
{
  public void InsertA()
  {
    //InsertCode
  }
}
class Credit
{
   public void InsertB()
  {
   // InsertCode
  }
}
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))

        {
            DebitBAL debit = new DebitBAL();
            CreditBAL credit = new CreditBAL();
            debit.InsertA();
            credit.InsertB();
            ts.complete();
}

我使用entity framework作为我的陈述。 在共享托管服务器中使用transaction scope是个好主意吗?

1 个答案:

答案 0 :(得分:0)

有关如何使用transaction scopes with entity framework

的信息,请参阅此链接

在此链接中,解释了三种情况,其中事务范围用于在更新多个实体期间发生错误时显示回滚:

1:当您对上下文进行多次保存调用时;

2:当您使用多个对象进行单次保存时;

3:和跨多个上下文的交易。