我正在使用EF的存储库模式。在我的项目中,我们使用两个数据库,这两个数据库位于两个不同的项目中。任何时候一个项目都是CoreLib(我们在另一个项目中指的是)。我有以下问题。
感谢您的回复。我已经实现了在事务范围内保存上下文更改的功能。每次都会抛出以下异常。
{"Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool."}
我认为这与MSDTC配置有关,我在客户端和SQL服务器机器中配置了网络DTC访问。配置如下。
Network DTS access - Enabled.
Allow Remote Clients - Enabled.
Allow Remote Administration – Enabled.
Allow Inbound - Enabled.
Allow outbond - Enabled.
No Authentication Required – Enabled.
配置MSDTC时是否有任何遗漏?
还有一个问题:此配置是否与域配置相关联? 因为在我们的环境中,我的数据库服务器没有使用其名称解析(我们使用的是IP地址)。
答案 0 :(得分:1)
我可以为这两个项目使用一个存储库层吗?
是
如何使用System.Transactions.TransactionScope提供交易安全性?注意:我使用的是Microsoft的统一框架和UnitOfWork模式。
在业务层中使用事务划分,因为业务需要它(在事务管理器中执行必须在一个事务中的所有事务)。
因为您正在使用UnitOfWork模式。
关于交易和EF的一些事情:
答案 1 :(得分:0)
FirstContext and
SecondContext`
public class ContextFacade : IUnitOfWork // your Unit of work interface
{
FirstContext _fc;
SecondContext _sc
public ContextFacade(FirstContext fc, SecondContext sc)
{
_fc = fc;
_sc = sc;
}
public void SaveChanges()
{
var scope = new TransactionScope(TransactionScopeOption.Required, options);
using(scope)
{
_fc.SaveChanges();
_sc.SaveChanges()
scope.Complete();
}
}
}
看看Ladislav Mrnka's answer如何将所有这些组合在一起。