Automapper CreateMissingTypeMaps property Warning

情到浓时终转凉″ 提交于 2019-12-12 04:30:31

问题


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);

But here AutoMapper gives warning.

I tried to add MapperConfiguration, but i have no idea how to use it in DynamicMap<>().

var config = new MapperConfiguration(cfg => { cfg.CreateMissingTypeMaps = true; });

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.


回答1:


Initialize static AutoMapper using a certain configuration (recommended for the usage you have show):

Mapper.Initialize(cfg => cfg.CreateMissingTypeMaps = true);

Or create instance of AutoMapper from a configuration:

var config = new MapperConfiguration(cfg => { cfg.CreateMissingTypeMaps = true; });
IMapper mapper = config.CreateMapper();

AutoMapper Static and Instance API



来源:https://stackoverflow.com/questions/39976989/automapper-createmissingtypemaps-property-warning

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