Elisabeth
Elisabeth

Reputation: 21206

Should I use AutoMapper from ViewModel to Model objects

I want to go the way doing all input validation in a viewmodel.

When the database is accessed the viewmodels data must be copied over to the model sent to database.

My concern is that data could be lost because:

Are my concerns justified or should I not care for that?

Upvotes: 2

Views: 555

Answers (2)

swapneel
swapneel

Reputation: 3061

My concern is that data could be lost because: Automapper is wrongly setup for certain scenarios thus properties are not copied over to the model Or Automapper is just not suited for every scenario maybe too complex ViewModels

I think it is unlikely that you will loose data. For complex viewModels you can choose to set specific properties manually which are not copied over by Automapper. As suggested by @feanz good Unit Test will provide you required assurance.**

Upvotes: 0

Richard Forrest
Richard Forrest

Reputation: 3616

Automapper is totally fine in this scenario I use it extensively for exactly this purpose. If you are worried about data lose should you not be making use of data annotation validation on the model itself to make sure you have the required data before persisting or calling some other service.

Also the only real way to make completely sure that you dont miss anything using Auotomapper or just manual code mapping is a good set of unit tests.

Upvotes: 2

Related Questions