31911

Question:
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 <strong>config</strong> variable for dynamic map?
Or is there any global setting for these issue because i used mapper for many times in my application.
Answer1: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();
<a href="https://github.com/AutoMapper/AutoMapper/wiki/Static-and-Instance-API#unsupported-operations" rel="nofollow">AutoMapper Static and Instance API</a>