Entity Framework InvalidOperationException when updating an item <p>I get an <code>System.InvalidOperationException</code> error which states:</p> <blockquote> <p>Additional information: Member 'IsModified' cannot be called for property 'state' because the entity of type 'BatteryItem' does not exist in the context. To add an entity to the context call the Add or Attach method of DbSet.</p> </blockquote> <p>Haven't I done exactly this? That is my method below:</p> <pre><code>public void UpdateBatteryState(BatteryItem batItem, BatteryState state) { try { batItem.state = state.ToString(); context.BatteryItem.Attach(batItem); var entry = context.Entry(batItem); entry.Property(x =&gt; x.state).IsModified = true; Save(); } catch (Exception e) { Console.WriteLine(e.Message); } } </code></pre>