问题
Does anyone know of a good (read: quick to code) method for converting DTOs to View Models or mapping DTO members to View Model members? Lately I've been finding myself writing many conversion and helper methods but this is a very arduous and tedious task. Moreover, it will often needs to be done twice (DTO -> View Model, View Model -> DTO).
Is there a methodology, technique, or technology which would allow me to do this more quickly and efficiently?
回答1:
Have a look at Automapper. It is an open source project that addresses exactly the problem you are having.
回答2:
As suggested by David, Automapper is highly flexible. If you have simple mapping need, check out the object mapping feature of Fasterflect, a library I co-authored. It offers very high performance (use CIL generation in the backend, instead of reflection) and is very easy to use.
回答3:
I found Otis Mapper better than AutoMapper , which facilitates mapping a collection of entities to DTO collection .
Please find the link below.
Otis
Hope this helps.
Thanks , Vijay
回答4:
I see automapper as the best solution for DTO Mapping
来源:https://stackoverflow.com/questions/3050848/converting-dtos-to-view-models