AutoMapper双向映射 [英] AutoMapper bidirectional mapping

查看:559
本文介绍了AutoMapper双向映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果要进行双向映射,是否需要创建两个映射?

If I want to do bi-directional mapping, do I need to create two mapping?

Mapper.CreateMap<A, B>() and Mapper.CreateMap<B, A>()?

推荐答案

是的,因为如果您更改某些属性的类型(例如DateTime-> string),则它不是双向的(您将需要指示Automapper如何进行转换)字符串-> DateTime).

Yes, because if you change the type of some property (for example DateTime -> string) it is not bidirectional (you will need to instruct Automapper how to convert string -> DateTime).

这篇关于AutoMapper双向映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆