我正在尝试在领域层使用TransactionScope
,以便可以跨(可能)多个存储库操作数据,但在同一个事务中保存所有数据。
我有以下保存方法:
public void Save(MyEntity source)
{
using (var scope = new TransactionScope())
{
var context = new MyEFEntities(environment.ConnectionString);
this.Repository.Add(source.ToDbMyEntity(), context);
context.SaveChanges();
scope.Complete();
}
}
但是在.SaveChanges()
时,我收到以下错误提示:
TransactionScope指定的事务与范围请求的值具有不同的隔离级别。参数名称:transactionOptions.IsolationLevel
这是什么原因导致的呢?