将 DTO 转换为视图模型
有谁知道将 DTO 转换为视图模型或将 DTO 成员映射到视图模型成员的好方法(阅读:快速编码)?最近,我发现自己编写了许多转换和辅助方法,但这是一项非常艰巨且乏味的任务。此外,它通常需要完成两次(DTO -> View Model,View Model -> DTO)。
是否有一种方法、技巧或技术可以让我更快、更高效地完成这项工作?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看看Automapper。这是一个开源项目,可以准确解决您遇到的问题。
Have a look at Automapper. It is an open source project that addresses exactly the problem you are having.
正如 David 所建议的,Automapper 非常灵活。如果您有简单的映射需求,请查看对象映射功能 Fasterflect,一个我共同创作的库。它提供非常高的性能(在后端使用 CIL 生成,而不是反射)并且非常易于使用。
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.
我发现 Otis Mapper 比 AutoMapper 更好,它有助于将实体集合映射到 DTO 集合。
请找到下面的链接。
Otis
希望这会有所帮助。
谢谢 ,
维杰
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
我认为 automapper 是 DTO 映射的最佳解决方案
I see automapper as the best solution for DTO Mapping