Converting DTOs to View Models

自古美人都是妖i 提交于 2019-12-13 13:14:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!