title: How to extend IdentityUser with custom property
body: <p>I'm using asp.net Identity 2.0 for users to log into my website, where the authentication details are stored in an SQL database. Asp.net Identity has been implemented in a standard way as can be found in many online tutorials.</p>
  
  <p>The <code>ApplicationUser</code> class in <code>IdentityModels</code> has been extended to include a custom property:</p>
  
  <pre><code>public class ApplicationUser : IdentityUser
  {
      public async Task&lt;ClaimsIdentity&gt; GenerateUserIdentityAsync(UserManager&lt;ApplicationUser&gt; manager, string authenticationType)
      {
         CookieAuthenticationOptions.AuthenticationType
         var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
         return userIdentity;
      }
      //My extended property
      public string Code { get; set; }
  }
  </code></pre>
  
  <p>When I register a new user I pass the <code>Code</code> custom property in the <code>RegisterBindingModel</code> but I'm not sure how to insert this custom property to the WebUsers table.</p>
  
  <p>I did as bellow but it doesn't actually inserting this property to the table together with the username and password.</p>
  
  <pre><code>var user = new ApplicationUser() { UserName = userName, Email = model.Email, Code=model.Code };
  </code></pre>
  
  <p>And the entire function:</p>
  
  <pre><code>[AllowAnonymous]
  [Route("Register")]
  public async Task&lt;IHttpActionResult&gt; Register(RegisterBindingModel model)
      {
          if (!ModelState.IsValid)
          {
              return BadRequest(ModelState);
          }
  
          var userName = !string.IsNullOrEmpty(model.UserName) ? model.UserName : model.Email;
          //I set it here but it doesn't get inserted to the table.
          var user = new ApplicationUser() { UserName = userName, Email = model.Email, Code=model.Code };
  
          IdentityResult result = await UserManager.CreateAsync(user, model.Password);
  
          if (!result.Succeeded)
          {
              return GetErrorResult(result);
          }
  
          return Ok();
      }
  </code></pre>
  
  <p>What am I missing?
  I was looking at similar questions but couldn't find an answer for this.</p>