title: Hitting an exception while updating an ENTITY, using EntityEntry in .Net Core
body: <p>Update Method:    </p>
  
  <pre><code>void IExpenseService.Update(Expense expenseItem)
      {
  
          //Create an Entity Entry object.
          var expense = context.Entry(expenseItem);
          if (expense != null)
          {
  
              if (expense.State!=EntityState.Detached)
              {
                  _context.Attach(expenseItem);
              }
              expense.State = EntityState.Modified;
          }
          context.SaveChanges();
      }
  </code></pre>
  
  <p>Stack Trace:</p>
  
  <pre class="lang-none prettyprint-override">
  System.InvalidOperationException was unhandled by user code
    HResult=-2146233079
    Message=The instance of entity type 'Expense' cannot be tracked because another instance 
    of this type with the same key is already being tracked. When adding new entities,
    for most key types a unique temporary key value will be created if no key is set (i.e. 
    if the key property is assigned the default value for its type). If you are explicitly 
    setting key values for new entities, ensure they do not collide with existing entities 
    or temporary values generated for other new entities. When attaching existing entities, 
    ensure that only one entity instance with a given key value is attached to the context.
    Source=Microsoft.EntityFrameworkCore
    StackTrace:
         at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.Add(TKey key, InternalEntityEntry entry)
         at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.StartTracking(InternalEntityEntry entry)
         at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState oldState, EntityState newState, Boolean acceptChanges)
         at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.PaintAction(EntityEntryGraphNode node)
         at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph(EntityEntryGraphNode node, Func`2 handleNode)
         at Microsoft.EntityFrameworkCore.DbContext.SetEntityState[TEntity](TEntity entity, EntityState entityState)
  </pre>