Automapper CreateMissingTypeMaps属性警告 [英] Automapper CreateMissingTypeMaps property Warning
问题描述
我认为这是一个重复的问题,但我无法解决. 这是我的地图.
I think this is a repeated Question but i am unable to resolve it. here is my mapping.
UserProfileVM model = AutoMapper.Mapper.DynamicMap<UserProfileVM>(objUser);
但是这里AutoMapper
发出警告.
我试图添加MapperConfiguration
,但是我不知道如何在DynamicMap<>()
中使用它.
I tried to add MapperConfiguration
, but i have no idea how to use it in DynamicMap<>()
.
var config = new MapperConfiguration(cfg => { cfg.CreateMissingTypeMaps = true; });
现在如何将我的 config 变量用于动态地图?
Now how to use my config variable for dynamic map?
或者这些问题是否有任何全局设置,因为我在应用程序中多次使用了映射器.
Or is there any global setting for these issue because i used mapper for many times in my application.
推荐答案
使用特定配置初始化静态AutoMapper(推荐用于您所展示的用法):
Initialize static AutoMapper using a certain configuration (recommended for the usage you have show):
Mapper.Initialize(cfg => cfg.CreateMissingTypeMaps = true);
或通过配置创建AutoMapper实例:
Or create instance of AutoMapper from a configuration:
var config = new MapperConfiguration(cfg => { cfg.CreateMissingTypeMaps = true; });
IMapper mapper = config.CreateMapper();
这篇关于Automapper CreateMissingTypeMaps属性警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!