Linq to sql multiple data context in same transaction

后端 未结 1 1421
梦谈多话
梦谈多话 2020-12-22 12:09

I am working on a project Where I have multiple reposetories to fetch data from differnt tables. All my repositories are independent, they create new dataContext, Add row t

相关标签:
1条回答
  • 2020-12-22 13:00

    TransactionScope can be used with multiple DataContexts, but as soon as more than one connection is involved the transaction is escalated to a MSDTC/XA/distributed transaction. For that to work you need to have MSDTC running on both the system where you code runs and on the database server.

    Alternatively, you can avoid escalation to a distributed transaction if you create an explicit connection within the transactionscope and pass that to your datacontexts; that way the TransactionScope will not escalate to a distributed transaction, and won't rely on MSDTC...

    0 讨论(0)
提交回复
热议问题