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:
ObjectStateEntry ose = myObjectContext.GetObjectState(myEntity);ose.ChangeState(EntityState.Unchanged);
Get Fluent Entity Framework now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.