Integrated Model Update in Message Creation and MVC Scenarios

Many people wrote about using Automapper to map objects (models) to view models, which I find very interesting and useful, but my question is how to do the opposite. I understand the complexity of this process and why Automapper does not work in this scenario, but I have to do this a lot with the publication of the form, especially when updating.

I have a model, I map it to the view model, and then present the form to the user. Then the form is submitted and, since the models can be quite complex, I use custom ModelBinders to process the response and build a new model that will not be saved directly. Instead, I load the original model from the database and call the method to update it from the published one without breaking anything. But it becomes repetitive and perhaps better suited.

The examples that I saw are very limited in model and naive, but in our application we can have more than 50+ publishing scripts like this one and growing ones.

+5
source share
1 answer

, , Mapper.Map()

(Mapper.CreateMap(). ConvertUsing()), ... string-y.

. ForMember (entity = > entity.Id, opt = > opt.Ignore()) ForMember (entity = > entity.ChildCollection, opt = > opt.UseDestinationValue()).

, , Mapper.Map(dto, entity).

+3

All Articles