want to get rid of ViewBag in my views so i've made a little research about viewmodels. i like the idea of using it for presentation, no questions here. but i don't realise what is the best way to use viewmodels for update.
first of all, why shouldn't i use my EF entities with [MetadataType(typeof(User_Validation))]?
public ActionResult Edit(User user)
{
...
}
where User is EntityObject.
then, if i however use viewmodels for it there is another question: here people believe that nested viewmodels should be used, but here is another opinion ("They are not wrappers around domain models", he says). Who is right?
also, what is the best way to update an object in action after POST (without using tryupdatemodel, because here and not only, people are against this approach). i've tried to use ApplyCurrentValues but if there is some complicated logic of update with many-to-many relations, for example, i get some huge EF errors. that's why i need to manually set fields of my EntityObject that i get from DB with values that come to action. Smth like this:
public ActionResult Edit(User user)
{
if (ModelState.IsValid)
{
var userToUpdate = usersRepository.Get(user.UserId);
userToUpdate.Field1 = user.Field1;
...
// save
}
...
}
where User is EntityObject with validation class.
so, if i use flat viewmodels to get values from form and AutoMapper to set values to my entityobject will it be the most right way to deal with updates or it can be automatized even more?