Automapper CreateMissingTypeMaps property Warning

2019-09-04 04:17发布

问题:

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