简体   繁体   English

使用 AutoMapper 对同一类型进行多个映射

[英]Multiple mappings for the same type using AutoMapper

I need help with my mapper program.我的映射程序需要帮助。 i have two types (Lets say A and B)and i want to have two different mappings.我有两种类型(比如说 A 和 B),我想要两种不同的映射。 In one method i want to use the first mapping between A and B and in other method i want to take the second.在一种方法中,我想使用 A 和 B 之间的第一个映射,而在另一种方法中,我想使用第二个。

I saw that "Mapper" Class is static, so i can't use CreateMap twice.我看到“映射器”Class 是 static,所以我不能使用 CreateMap 两次。

Is this possible?这可能吗?

thanks.谢谢。

Instead of using the static Mapper class, you can create different instances of the underlying MappingEngine and configuration classes.您可以创建底层 MappingEngine 和配置类的不同实例,而不是使用 static Mapper class。 Then you can configure the instances differently.然后,您可以以不同方式配置实例。

Update: see also this answer .更新:另见这个答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM