As mentioned by @anon you can’t attach model once you loaded the entity with the same key. The changes must be applied to attached entity. Instead of this:
db.Entry(model).State = EntityState.Modified;
use this:
db.Entry(v).CurrentValues.SetValues(model);
More Related Contents:
- Create a Dropdown List for MVC3 using Entity Framework (.edmx Model) & Razor Views && Insert A Database Record to Multiple Tables
- MVC3 and Code First Migrations – “model backing the ‘blah’ context has changed since the database was created”
- Stuffing an anonymous type in ViewBag causing model binder issues
- Nullable property to entity field, Entity Framework through Code First
- Entity Framework Validation confusion – maximum string length of ‘128’
- Entity Framework: One Database, Multiple DbContexts. Is this a bad idea? [closed]
- Entity Framework and SQL Server View
- MVC, EF – DataContext singleton instance Per-Web-Request in Unity
- EntityFramework code-first custom connection string and migrations
- Debug code-first Entity Framework migration codes
- How to warm up an ASP.NET MVC application on IIS 7.5?
- Unique keys in Entity Framework 4
- Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths
- Entity Framework: Re-finding objects recently added to context
- ObjectContext.Refresh()?
- Place to put Database.SetInitializer
- How do I map a char property using the Entity Framework 4.1 “code only” fluent API?
- combination of two field must be unique in Entity Framework code first approach. how it would?
- mapping private property entity framework code first [duplicate]
- EntityFramework Core automatic migrations
- Entity Framework 4.1+ many-to-many relationships change tracking
- what is difference between a Model and an Entity
- Mocking or faking DbEntityEntry or creating a new DbEntityEntry
- Include Grandchildren in EF Query
- Changes in IDENTITY column after EF core 3
- What would cause the Entity Framework to save an unloaded (but lazy loadable) reference over existing data?
- Using the Entry().CurrentValues.SetValues() is not updating collections
- Entity Framework Code First Many to Many Setup For Existing Tables
- .NET 4.5 Beta DbGeography NotImplementedException
- Why does the entity framework need an ICollection for lazy loading?