title: In EF6 is it possible to perform a transaction across service calls with a context per call structure?
body: <p>I have a structure set up with multiple service calls to a WCF service on a server. I have multiple DbContexts instantiated per call. I would like to group some of these calls into a single transaction on the server, while excluding other calls that might occur in the mean time. Is this possible? </p>
  
  <p>My contexts are all managed within a single application on a single server and all contexts use the same connection string. </p>
  
  <p>I am looking for something like</p>
  
  <pre><code>var transKey = transService.BeginTransaction(); // creates a transaction of some kind.
  service1.Execute(transKey); // on the server places the execution within the specified transaction.
  service2.Execute(transKey); // same here
  transService.CommitTransaction(transKey); // Nothing happens until now (allowing other clients to freely utilize service1 without touching the transaction), the transaction occurs, and everything gets cleaned up.
  </code></pre>
  
  <p>But I may barking up the wrong tree so to speak. Any help in finding a solution to this problem would be useful.</p>
  
  <p>EDIT</p>
  
  <p>What I am wanting to do is have a specified transaction that spans multiple service calls, but not every service call. I am looking for a mechanism to create a transaction, then decide "I want this DbContext action and this other DbConext action, but not this DbContext action part of the transaction". Then have the liberty to hold that transaction until I am ready to execute it. TransactionScope I believe does not give me that kind of control.</p>
  
  <p>I may be wrong but TransactionScope appears to create a single transaction per connection, and any and every DbContext action gets rolled up into the transaction as long as the scope is alive. I need more control over what goes into such and such a transaction.</p>