I’m creating an Asp.net MVC site using the Entity Framework and am wondering how to keep new and updated entities in memory across multiple requests without committing to the database.
Say, for example a user goes to a view for editing an entity, and on that view they can add children to the entity. I would like to not commit the change to the database until the user clicks the “Save” button on the page.
I’ve picked up that I’m not to persist the ObjectContext, which I understand. Essentially I want to take an entity, keep it in Session state, or somewhere equivalent, make changes there, then submit those to the database when the user has finished on the page.
Any thoughts on how to do this?
I’m creating an Asp.net MVC site using the Entity Framework and am wondering how
Share
The ViewData collection is a temporary “scratch-pad” for persisting objects across requests. It works in the same manner as the Session object, but is shorter-term in lifetime.
In the default MVC project, you can see an example of this in the Home controller, where it uses the ViewData[“Message”] to display a message on the Index view.