I need to realize transaction under two models (using two separated bounded contexts). So code like this:
using (TransactionScope scope = new TransactionScope())
{
//Operation 1
using(var context1 = new Context1())
{
context1.Add(someCollection1);
context1.SaveChanges();
}
//Operation 2
using(var context2 = new Context2())
{
context2.Add(someCollection2);
context2.SaveChanges();
}
scope.Complete();
}
return the exception:
An ambient transaction has been detected. Entity Framework Core does not support ambient transactions. See http://go.microsoft.com/fwlink/?LinkId=800142
In Link they advice to use one connection for two context. And use context2 in using block of context1.
But if I use own controller/service for every model:
using (TransactionScope scope = new TransactionScope())
{
service1.DoWork();
service2.DoWork();
scope.Complete();
}
How should I implement this? Add connection as parameter in method - seems absurdly. Init service with connection also bad idea.