title: How to insert values into virtual fields
body: <p>I have a learner table that i set values to on a user registration, 'Register(RegisterViewModel model)' in the AccountController. </p>
  
  <pre><code> if (result.Succeeded)
              {
                  await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
  
  
                  using (The_FactoryDBContext db = new The_FactoryDBContext())
                      {
                          Learner learner = new Learner();
  
                          learner.learnerID = User.Identity.GetUserId();
                          learner.llCounter = 0;
                          learner.dtwCounter = 0;
                          learner.ftwCounter = 0;
                          learner.counter = 0;
  
                          db.Learners.Add(learner);
                          db.SaveChanges();
                      }
                  }
         }
  </code></pre>
  
  <p>This is how my learner auto generated class looks with some virtual fields.</p>
  
  <pre><code>public partial class Learner
  {
      public Learner()
      {
          this.Learner_Treasure = new HashSet&lt;Learner_Treasure&gt;();
      }
  
      public string learnerID { get; set; }
      public int llCounter { get; set; }
      public int dtwCounter { get; set; }
      public int ftwCounter { get; set; }
      public int counter { get; set; }
  
      public virtual AspNetUser AspNetUser { get; set; }
      public virtual ICollection&lt;Learner_Treasure&gt; Learner_Treasure { get; set; }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>However i get this error upon registration and i dont know how to fix it, can someone help me, or is my code perhaps in the wrong place? </p>
  
  <blockquote>
    <p>The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Learner_AspNetUsers1". The conflict occurred in database "The_Factory", table "dbo.AspNetUsers", column 'Id'.</p>
  </blockquote>
  
  <p>AspNetUser class </p>
  
  <pre><code>public partial class AspNetUser
  {
      public AspNetUser()
      {
          this.AspNetUserClaims = new HashSet&lt;AspNetUserClaim&gt;();
          this.AspNetUserLogins = new HashSet&lt;AspNetUserLogin&gt;();
          this.AspNetRoles = new HashSet&lt;AspNetRole&gt;();
      }
  
      public string Id { get; set; }
      public string Email { get; set; }
      public bool EmailConfirmed { get; set; }
      public string PasswordHash { get; set; }
      public string SecurityStamp { get; set; }
      public string PhoneNumber { get; set; }
      public bool PhoneNumberConfirmed { get; set; }
      public bool TwoFactorEnabled { get; set; }
      public Nullable&lt;System.DateTime&gt; LockoutEndDateUtc { get; set; }
      public bool LockoutEnabled { get; set; }
      public int AccessFailedCount { get; set; }
      public string UserName { get; set; }
      public int AvatarID { get; set; }
  
      public virtual ICollection&lt;AspNetUserClaim&gt; AspNetUserClaims { get; set; }
      public virtual ICollection&lt;AspNetUserLogin&gt; AspNetUserLogins { get; set; }
      public virtual Avatar Avatar { get; set; }
  
      public virtual Learner Learner { get; set; }
      public virtual ICollection&lt;AspNetRole&gt; AspNetRoles { get; set; }
  }
  </code></pre>
  
  <p>}</p>