public void Put(Pedido pedido) { var local = _context.Set <Pedido>() .Local .FirstOrDefault(entry => entry.Id.Equals(pedido.Id)); // check if local is not null if (local != null) { // detach _context.Entry(local).State = EntityState.Detached; } // set Modified flag in your entry _context.Entry(pedido).State = EntityState.Modified; }