title: Automatically update ID value for records retrieved
body: <p>So, consider the following class:</p>
  
  <pre><code>public class Solution
  {
      [Key]
      public int Id { get; set; }
  
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>And the following methods</p>
  
  <pre><code>public void DoSomething()
  {
      new Item originalItem = new Item();
      item.Name = "Test";
  
      InserIntoDb(originalItem);
  
      Assert.True(item.Id != 0);
  }
  
  public void InserIntoDb(Item item)
  {
      context.Item.Add(item);
      context.SaveChanges();
  }
  </code></pre>
  
  <p>On this case, after insert into the db, EF automatically updates the originalItem with its auto generated ID value. </p>
  
  <p>My problem starts when I add some logic to only add to the db if the Name doesn't exist. If exists the Insert doesn't happen therefore the ID property is not populated.</p>
  
  <p>My question is: Is there a way to make the context.Item (when retrieving all) to automatically update the ID of the originalItem value without having to change the InsertIntoDb method to return an Item and consequently having to add a line like</p>
  
  <pre><code>originalItem = InsertIntoDb(originalItem);
  </code></pre>
  
  <p>Thanks, in advance </p>