title: Transactions with ASP.NET Identity UserManager
body: <p>I'm trying to update a user. </p>
  
  <pre><code>AppUserManager appUserManager = HttpContext.GetOwinContext().GetUserManager&lt;AppUserManager&gt;();
  
  AppUser member = await appUserManager.FindByIdAsync(User.Identity.GetUserId());
  
  member.HasScheduledChanges = true;
  
  IdentityResult identityResult = appUserManager.Update(member);
  </code></pre>
  
  <p>If a subsequent call to a Web API fails, I need to roll back any changes to the user. I know about transactions, like this:</p>
  
  <pre><code>using (var context = HttpContext.GetOwinContext().Get&lt;EFDbContext&gt;())
   {
      using (var dbContextTransaction = context.Database.BeginTransaction())
      {      
          try
          {   
              // Changes
  
              member.HasScheduledChanges = true;
  
              // Would this be transactional?
              IdentityResult identityResult = appUserManager.Update(member);               
  
              context.SaveChanges();
  
              dbContextTransaction.Commit();
          }
          catch //(Exception ex)
          {
  
              // dbContextTransaction.Rollback(); no need to call this manually.
          }
      }
  }
  </code></pre>
  
  <p>But will operations done with AppUserManager inside the try block be transactional? Also, do they use the same instance of EFDbContext? In other words, I don't know if var context at the start of the second code example would be used by the appUserManager "Update" method call in the try block. </p>
  
  <p>Also, AppUserManager is created like this:</p>
  
  <pre><code>public static AppUserManager Create(IdentityFactoryOptions&lt;AppUserManager&gt; options, IOwinContext context)
  {           
  
      EFDbContext db = context.Get&lt;EFDbContext&gt;();
  
      AppUserManager manager = new AppUserManager(new UserStore&lt;AppUser&gt;(db));
  
      // etc.
  
      return manager;
  }
  </code></pre>