title: User manager CreateAsync running very slow - Identity 2
body: <p>I'm running this query to import uses from an old MySQL database to a new SQL database using entity framework and Microsoft's Identity 2 and on the local server Visual Studio Community edition runs alongside SQL Server 10.0.5</p>
  
  <p><strong>User manager declaration</strong></p>
  
  <pre><code>private ApplicationUserManager _userManager;
  public ApplicationUserManager UserManager
  {
      get
      {
          if (_userManager == null)
          {
              this._userManager = HttpContext.GetOwinContext().GetUserManager&lt;ApplicationUserManager&gt;();
              this._userManager.PasswordValidator = new CustomPasswordValidator();
          }
          return _userManager;
      }
      private set
      {
          _userManager = value;
      }
  }
  </code></pre>
  
  <p><strong>Controller methods</strong> - <em>the sql and MySQL unit of work are in the controller construct, only 1 context per db is made for this entire process</em></p>
  
  <pre><code>public async Task&lt;ActionResult&gt; Index()
  {
      await ImportUsers();
  
      return View();
  }
  
  private async Task&lt;bool&gt; ImportUsers()
  {
      DateTime timeNow = DateTime.Now;
  
      // Returns a full list of old users in about a millisecond
      List&lt;default_users&gt; users = 
          this.mySQLUnitOfWork
          .MySQLRepo
          .GetUsers()
          .ToList(); 
  
      foreach (var user in users)
      {                  
          if (user.username != null &amp;&amp; user.email != null &amp;&amp;
              user.username != "" &amp;&amp; user.email != "" &amp;&amp;
              UserManager.FindByEmail(user.email) == null)
          {
              default_profiles profile = 
                  this.mySQLUnitOfWork
                      .MySQLRepo
                      .GetProfiles()
                      .Where(x =&gt; 
                          x.id == user.id
                      ).FirstOrDefault();
  
              if (profile != null)
              {          
                  var newUser = new ApplicationUser { 
                      UserName = user.username.ToLower(), 
                      Email = user.email.ToLower(), 
                      CreatedAt = timeNow, 
                      UpdatedAt = timeNow 
                  };
  
                  newUser.Profile = new UserProfile { 
                      CreatedAt = timeNow, 
                      UpdatedAt = timeNow, 
                      FirstName = profile.first_name, 
                      LastName = profile.last_name, 
                      User = newUser 
                  };
  
                  // Takes ages to complete
                  var result = await UserManager.CreateAsync(
                      newUser, 
                      Guid.NewGuid().ToString("N")
                  );
  
                  if (result.Succeeded)
                  {
                      UserManager.AddToRole(newUser.Id, RoleChoices.MEMBER);             
                      var dbUser = this.sqlUnitOfWork.UserRepository.GetByID(newUser.Id);
                  }
              }
          }
      }
  
      return true;
  }
  </code></pre>
  
  <p><strong>Problem:</strong></p>
  
  <p><strong><em>This operation takes at least 45 minutes for 2000 user records</em></strong>. It seems that the CreateAsync and AddToRole methods take absolutely ages to run. Any reasons why this might be?</p>
  
  <p><strong>Note:</strong></p>
  
  <p>I have been debugging this to death... The slowest part is waiting for the CreateAsync method to complete... It's really quite odd? It takes atleast 1 second to create a user.</p>