title: Prevent Adding New Record on Related Table Entity in Entity Framework
body: <p>I am trying to add new record on my entity. It works fine, the problem is, the related entities are adding new records as well. Is there a way to stop related or 2nd level entities to be inserting new records as well?</p>
  
  <p>Here is my sample Entity Class:</p>
  
  <pre><code>public Tracking()
      {
          public string Details { get; set; }
  
          //Other properties here..
  
          [Required]
          public virtual Employee { get; set; }
      }
  </code></pre>
  
  <p>Basically I am just getting the existing Employee record then declare it on my property, then add the the Tracking record:</p>
  
  <pre><code>Employee emp = _dbContext.EmployeeRepo.GetEmployeeByID(1001);
  
  Tracking track = new Tracking()
  {
     Details = "My details here",
     Employee = emp 
  }
  
  _dbContext.TrackingRepo.Add(track);
  _dbContext.SaveChanges();
  </code></pre>
  
  <p>This code works fine, the problem is that, another new Employee Record is inserted on my table Employee. Which is not what I want. I just want to add a new record of Tracking with the existing employee record. </p>
  
  <p>So is there a way to do this or I am missing a configuration or code with my Entity Framework?</p>