title: Link ASP.Net Identity table to a user detail table
body: <p>I am trying to link my Identity user table to a user detail table I have created to track other user information. That user detail table is called UserProfile.</p>
  
  <p>I came across this link but it is not working in .NET Core 2.1:
  <a href="https://stackoverflow.com/questions/33197402/link-asp-net-identity-users-to-user-detail-table">Link ASP.NET Identity users to user detail table</a></p>
  
  <p>Here is what I have currently:</p>
  
  <pre><code>public class ApplicationUser : IdentityUser
  {
  
      [Key]
      public override string Id { get; set; }
  
      [ForeignKey("Id")]
      public virtual UserProfile UserProfile { get; set; }
  
  }
  
  [Table("UserProfile")]
  public class UserProfile
  {
      [Key, ForeignKey("User")]
      public string UserId { get; set; } // UserId (Primary key) 
      public string UserName { get; set; } // UserName 
      public string FirstName { get; set; } // FirstName
      public string LastName { get; set; } // LastName
  
      //[ForeignKey("Id")]
      public virtual ApplicationUser User { get; set; }
  }
  </code></pre>
  
  <p>However, elsewhere in the code I call:</p>
  
  <pre><code>var user = await _userMgr.FindByNameAsync(model.UserName);
  </code></pre>
  
  <p>And user.UserProfile is null.</p>
  
  <p>I have tried many combinations of data annotations and even fluent api to no avail.</p>
  
  <pre><code>   modelBuilder.Entity&lt;ApplicationUser&gt;()
         .HasOne(c =&gt; c.UserProfile)
         .WithOne(t =&gt; t.User)
         .HasForeignKey&lt;UserProfile&gt;(b =&gt; b.UserId);
  </code></pre>
  
  <p>I also tried turning on lazy loading but that couldn't even load the property.</p>
  
  <p>Does anyone know how to do this in .Net Core 2.1?</p>
  
  <p>Thanks</p>