title: MVC 5 UserManager: The entity type ApplicationUser is not part of the model for the current context
body: <p>I'm trying (but failing) to implement the MVC <code>UserManager</code> to my website. I thought my case is fairly trivial. I have a <code>User</code> class (Entity Framework - Database first) which contains all the user's info. Not every user from the <code>User</code> has access to the website. So in my ApplicationUser there is a link to this class. In code it looks like this:</p>
  
  <pre><code>public partial class User
  {
      public int Id { get; set; }
      public string Firstname { get; set; }
      public string Lastname { get; set; }
      public string Email { get; set; }
  }
  
  public class ApplicationUser : IdentityUser
  {
      public virtual Entities.User UserInfo { get; set; }
  
      public ApplicationUser()
      {
          UserInfo = new Entities.User();
      }
  }
  </code></pre>
  
  <p>When invoking the <code>CreateUserAsync</code>-method in the controller, it all goes wrong. Below you can find my controller code.</p>
  
  <pre><code>public class AccountController : BaseController
  {
      public UserManager&lt;ApplicationUser&gt; UserManager { get; private set; }
  
      public async Task&lt;ActionResult&gt; Register(RegisterViewModel model)
      {
          if (ModelState.IsValid)
          {
              var dbUser = new User 
              { 
                  Firstname = model.FirstName, 
                  Lastname = model.LastName, 
                  Email = model.UserName 
              };
              db.Users.Add(dbUser);
              db.SaveChanges();
  
              var appUser = new ApplicationUser(model.UserName);
              appUser.UserInfo = dbUser;
  
              try
              {
                  var result = await UserManager.CreateAsync(appUser, model.Password);
              }
              catch (Exception e)
              {
                  db.Users.Remove(dbUser);
                  db.SaveChanges();
              }
          }
      }
  }
  </code></pre>
  
  <p>The <code>CreateUserAsync</code>-method gives the following error: <code>The entity type ApplicationUser is not part of the model for the current context.</code></p>
  
  <p>Now my questions:</p>
  
  <ol>
  <li>Am I doing this the 'mvc'-way? I feel this is a lot of work for something that in my opinion is trivial.</li>
  <li>If not, is there a better way to achieve this?</li>
  </ol>