我在使用事务范围时遇到问题,它没有回滚。这是我的代码,我正在使用
实体版本6.1.3和 Firebird ADO.NET Provider版本5.8.0
我使用了2个数据库,一个用于数据,另一个用于文件。我需要同时提交或不提交
[TestMethod]
public void TestMultiRepositorio()
{
//UOW uow = new UOW();
//var repoCliente = uow.IncluiOuObtemRepositorioTipado<ClientesRepositorio>();
//var repoDocumento = uow.IncluiOuObtemRepositorioTipadoGED<DocumentosRepositorio>();
//new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = IsolationLevel.ReadCommitted })
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress))
using (IContexto ctx = new ContextoInterlitis())
using (IContexto ctxGED = new ContextoGED())
{
IRepository<Cliente> repoCliente = new ClientesRepositorio(ctx);
IRepository<Documento> repoDocumento = new DocumentosRepositorio(ctxGED);
var listaClientes = repoCliente.Buscar(c => c.Nome.Contains("Prefeitura"));
var cliente = listaClientes.FirstOrDefault();
cliente.Nome = "Teste";
ctx.SaveChanges();
var documento = new Documento() { CaminhoDocumento = @"D:\Formatador.txt" };
//Add
repoDocumento.Incluir(documento);
//Rollback?
throw new Exception("Teste!");
ctxGED.SaveChanges();
cliente.Nome = "Prefeitura de Teste Alterada";
ctx.SaveChanges();
scope.Complete();
}
}