title: EF Core not saving ParentId
body: <p>I am trying to build up a structure of 'Job' objects. These are used to describe an entire process a person would need to do.</p>
  
  <p>For example.</p>
  
  <p>If the Job had the description "Make Coffee", it would have a List of other jobs that when done all together result in making a coffee.</p>
  
  <p>An example structure might be:</p>
  
  <pre><code>Make Coffee
    |- Boil Kettle
       |- Fill Kettle
       |- Turn on Kettle
    |- Get a cup
    |- Place instant coffee in the cup
    |- Pour boiling water in the cup
    |- Add milk to the cup
  </code></pre>
  
  <p>It should also be noted, each Job has a version number; and VersionOfID. This is in case a job needs to be changed, only one version is 'Live' and is the one that will be used.</p>
  
  <p>I am adding objects to the EF Core DBContext, and before I call SaveChanges, I can see the structure correctly; However, once the context is closed/reloaded the jobs no longer reference each other. I can see in SQL Management studio the ParentID is null for all the objects.</p>
  
  <p>The class for Job is as follows:</p>
  
  <pre><code>public class Job
  {
      public int JobId { get; set; }
  
      [Required]
      public string Description { get; set; }
  
      public string Code { get; set; }
  
      public int Quantity { get; set; } = 1;
  
      public int Time { get; set; }
  
      public TimeUnit UnitOfTime { get; set; }
  
      [ForeignKey("VersionOf")]
      public int? VersionOfId { get; set; }
      public virtual Job VersionOf { get; set; }
  
      public int JobVersion { get; set; } = 1;
  
      [ForeignKey("Parent")]
      public int? ParentId { get; set; }
      public virtual Job Parent { get; set; }
  
      public virtual List&lt;Job&gt; Jobs { get; set; } = new List&lt;Job&gt;();
  
      public void AddJob(Job job)
      {
          job.Parent = this;
          Jobs.Add(job);
      }
  }
  
  public enum TimeUnit
  {
      Seconds,
      Minutes,
      Hours,
      Days,
      Weeks,
      Months,
      Years
  } 
  </code></pre>
  
  <p>I am adding them to the context like this:</p>
  
  <pre><code>        DatabaseContext dbContext = new DatabaseContext();
  
          Job PK3 = new Job()
          {
              Code = "PK3",
              Description = "Scan Item",
              Time = 7,
              UnitOfTime = TimeUnit.Seconds,
          };
          dbContext.Jobs.Add(PK3);
  
          Job PK4 = new Job()
          {
              Code = "PK4",
              Description = "Pick Item",
              Time = 15,
              UnitOfTime = TimeUnit.Seconds,
          };
          dbContext.Jobs.Add(PK4);
  
          Job PK5 = new Job()
          {
              Code = "PK5",
              Description = "Walk To Item",
              Time = 60,
              UnitOfTime = TimeUnit.Seconds,
          };
          dbContext.Jobs.Add(PK5);
  
          Job OP1 = new Job()
          {
              Code = "OP1",
              Description = "Entire Item Pick",
              Quantity = 1,
          };
  
          OP1.AddJob(PK5);
          OP1.AddJob(PK4);
          OP1.AddJob(PK3);
  
          dbContext.Jobs.Add(OP1);
  
          try
          {
              int a =  dbContext.SaveChanges();
          }
          catch (Exception e)
          {
              Console.WriteLine(e);
              throw;
          }
  </code></pre>
  
  <p>You can see how the table looks here:
  <a href="https://i.stack.imgur.com/TueDp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TueDp.png" alt="table with NULL IDs"></a></p>
  
  <p>I thought it might be todo with LazyLoading, which I have enabled with:</p>
  
  <pre><code>    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
      {
          optionsBuilder.UseSqlServer(@"&lt;--snip--&gt;");
          optionsBuilder.UseLazyLoadingProxies();
      }
  </code></pre>
  
  <p>However, I have removed this and this issue continues.</p>
  
  <p>Does anyone know how to fix this?</p>