title: How to clone an entity in Entity Framework Core?
body: <p>I'm trying to clone an entity using the SetValues method but I get the following error :</p>
  
  <p><em>The instance of entity type 'TariffPeriod' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached.</em> </p>
  
  <p>Here is the code : </p>
  
  <pre><code>var period2 = _tariffRepository.GetPeriodFull(period.GUID);
  var period3 = new TariffPeriod();
  _appDbContext.TariffPeriods.Add(period3);
  _appDbContext.Entry(period3).CurrentValues.SetValues(period2);
  </code></pre>
  
  <p>I see that the error is due to the value of the primary key being copied into the new entity. So, how do I copy the values without the key?</p>
  
  <p>Thanks for your help
  Eric</p>