【问题标题】:Should I use transacion scope in a shared hosting server?我应该在共享托管服务器中使用事务范围吗?
【发布时间】:2013-04-20 07:30:53
【问题描述】:

假设我必须使用不同的方法并将它们放在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 是个好主意吗?

【问题讨论】:

标签: asp.net entity-framework transactionscope


【解决方案1】:

transaction scopes with entity framework的使用方法见此链接

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

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

2:当你有多个对象的单个保存时;

3:跨多个上下文的事务。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 2012-07-17
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多