title: How to implement ambient transaction in Entity Framework Core?
body: <p>I need to realize transaction under two models (using two separated bounded contexts). So code like this:</p>
  
  <pre><code>  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();
     }
  </code></pre>
  
  <p>return the exception:</p>
  
  <blockquote>
    <p>An ambient transaction has been detected. Entity Framework Core does
    not support ambient transactions. See
    <a href="http://go.microsoft.com/fwlink/?LinkId=800142" rel="noreferrer">http://go.microsoft.com/fwlink/?LinkId=800142</a></p>
  </blockquote>
  
  <p>In Link they advice to use one connection for two context. And use context2 in using block of context1. </p>
  
  <p>But if I use own controller/service for every model:</p>
  
  <pre><code>using (TransactionScope scope = new TransactionScope())
  {  
        service1.DoWork();
        service2.DoWork();
  
         scope.Complete();
   }
  </code></pre>
  
  <p>How should I implement this? Add connection as parameter in method - seems absurdly. Init service with connection also bad idea.</p>