O'Reilly logo

Fluent Entity Framework by Rebecca M. Riordan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Entity undo

When I’m working, there are two things that I really, really wouldn’t want to do without: coffee, and Ctrl+Z Undo. Of course most modern UI platforms provide Ctrl+Z at a control level, but what about throwing away all the changes a user has made to an entity? It’s a common (and perfectly reasonable) request, but prior to Entity Framework and state entries, it was difficult to implement. Now, it’s trivial:

Using the objectcontext

The ObjectStateEntry.State property is read-only, but you can call its ChangeState() method:

Image

ObjectStateEntry ose = myObjectContext.GetObjectState(myEntity);ose.ChangeState(EntityState.Unchanged);

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required