title: Using EF transaction across libraries
body: <p>I have this class A that begins an EF transaction where UserDb is my DbContext</p>
  
  <pre><code> using (DbContextTransaction dbTransaction = UserDb.Database.BeginTransaction(IsolationLevel.ReadUncommitted))
  </code></pre>
  
  <p>Then I have several inserts and there is a need to call another library [which essentially lives on the same server in the bin folder] to do another insert. </p>
  
  <pre><code>new ExtLibrary().CreatePoweruser(3, UserDb);
  </code></pre>
  
  <p>As you can see I am passing the same connection. And this statement is within the top using which I thought would mean that everythign is in the same transaction.</p>
  
  <p>Extlibrary code:</p>
  
  <blockquote>
    <p>Data.Entities.User UserEntity = new Data.Entities.User            {</p>
  
  <pre><code>            UserTypeId =34,
  
              CreatedDate = DateTime.Now,
              CreatedBy = "mk92Test",
                         };
          UserDb.Users.Add(UserEntity);
          UserDb.SaveChanges();
  </code></pre>
  </blockquote>
  
  <p>Everything works unless the ExtLibrary insert fails. Control comes back to the parent class which has rollback code on exception and I get an The underlying provider failed on rollback. But the first set of inserts certainly do rollback even after this exception. </p>
  
  <p>Please advise.</p>