title: Add object as property in ASP.Net identity
body: <p>I'm using MVC 5 ASP.net Identity entity framework code-first to create an online application form. I have created a new project with the ASP.net identity scaffold, and need to be able to add additional properties. Some of them are simple properties- mobile phone number etc, and this works fine. however I need to add a more complex object to the user to store the application form information. I tried doing this:</p>
  
  <pre><code>public class ApplicationUser : IdentityUser 
  {
      public string Title { get; set; }
      public string FirstName { get; set; }
      public string  Surname { get; set; }
      public override string PhoneNumber { get; set; }
      public string  PracticeName { get; set; }
      public string  Address { get; set; }
      public string  Mobile { get; set; }
      public string  GMCNumber { get; set; }
      public AppForm ApplicationForm { get; set; } 
  
      public async Task&lt;ClaimsIdentity&gt; GenerateUserIdentityAsync(UserManager&lt;ApplicationUser&gt; manager)
      {
          // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
          var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
          // Add custom user claims here
          return userIdentity;
      }
  }
  
  public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
  {
      public ApplicationDbContext()
          : base("DefaultConnection", throwIfV1Schema: false)
      {
      }
  
      public DbSet&lt;AppForm&gt; AppForms { get; set; }
      public DbSet&lt;AppFormDocument&gt; AppFormDocuments { get; set; }
      public DbSet&lt;AppFormAnswer&gt; AppFormAnswers { get; set; }
  
      public static ApplicationDbContext Create()
      {
          return new ApplicationDbContext();
      }
  }
  </code></pre>
  
  <p>and have created the appform models like this:</p>
  
  <pre><code>public class AppForm {
  
      public int Id { get; set; }
      public int PercentComplete { get; set; }
      public string Status {get; set; }
      public bool Completed { get; set; }
      public bool Reviewed { get; set; }
      public bool SignedOff { get; set; }
      public int LastPageCompleted { get; set; }
  
      public List&lt;AppFormDocument&gt; Documents { get; set; }
      public List&lt;AppFormAnswer&gt; Answers { get; set; }
  
  }
  
  public class AppFormDocument {
      public int Id { get; set; }
      public DateTime DateSubmitted { get; set; }
      public string Name { get; set; }
      public DateTime? ExpiryDate { get; set; }
      public bool Accepted { get; set; }
      public string ScannedFile { get; set; }
  }
  
  
  public class AppFormAnswer {
      public int Id { get; set; }
      public string QuestionNumber { get; set; }
      public string Question { get; set; }
      public string Answer { get; set; }
  }
  </code></pre>
  
  <p>The application form is very large and has many questions which is why I didnt just put it all in the applicationuser class. There is also the requirement to upload documents with the form. </p>
  
  <p>Now, when I create the user and attach an instance of the AppForm and some instances of AppFormAnswers to it, then save it, the data gets stored successfully, but when I try to access the data again after logging in, it is not found. The additional simple properties of the user are available though, including mobile number and title. here's my code: </p>
  
  <pre><code>[Route("appform/{action}")]
  [Authorize]
  public class AppFormController:Controller {
      // GET: AppForm
      public ActionResult Index() {
          ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager&lt;ApplicationUserManager&gt;().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());
  
          var model = new AppFormIndexViewModel();
          if (user != null) {
              if (user.ApplicationForm != null) {
                  model.PercentComplete = user.ApplicationForm.PercentComplete;
                  model.NextPage = "Page" + user.ApplicationForm.LastPageCompleted + 1;
                  model.Status = user.ApplicationForm.Status;
              } else {
                  // if appform is not available for user for some reason, create a new one.
                  user.ApplicationForm = new AppForm { PercentComplete = 0, Reviewed = false, Status = "Incomplete", SignedOff = false, Completed = false, LastPageCompleted = 0 };
                  var uManager = new UserManager&lt;ApplicationUser&gt;(new UserStore&lt;ApplicationUser&gt;(new ApplicationDbContext()));
                  uManager.UpdateAsync(user);
  
                  model.PercentComplete = 0;
                  model.Status = "Incomplete";
                  model.NextPage = "Page1";
              }
          }
          return View(model);
      }
  </code></pre>
  
  <p>Now when the uManager.UpdateAsync(user) line runs, the data is saved to the database fine and a new appForm record is added. The database automatically creates primary keys and foreign keys for all the tables too.</p>
  
  <p>So, do I need to write an overload of the login method to retrieve the data from the other tables? Or do I need to add something to the ApplicationDbContext class? </p>
  
  <p>This is my first MVC application so not really sure where to turn now. Have tried reading many forum posts and blogs but not found anything that really matches my needs. A lot of information relates to earlier version of mvc which do not work with the newer asp.net identity system.</p>