Following this tutorial (http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/handling-concurrency-with-the-entity-framework-in-an-asp-net-mvc-application), I learned how to save data and do concurrency checks on data before the data is submitted.
Now, I have a view that uses a ViewModel instead of the actual data model.
(1) How do I save the data back to the database when the form posts?
I can no longer call db.SaveChanges(); because the data is in the type of ViewModel instead of Model.
(2) How do I perform a concurrency check on the data?
I’m just looking for a simple example to follow.
Thanks!
It works the same way, but you have to copy the data from the ViewModel to the Data Model when it’s submitted, or you need to construct a new Entity from the view model and attach it to the DbSet.
You can use a tool such as AutoMapper to ease this process.