Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoMapper.Mapper does not contain definition for CreateMap

This might be a basic question but wondering I am not getting AutoMapper.Mapper.CreateMap method.

enter image description here

Am I using wrong AutoMapper reference/package? Thanks

like image 235
Sami Avatar asked Jul 05 '16 01:07

Sami


People also ask

When should you not use AutoMapper?

If you have to do complex mapping behavior, it might be better to avoid using AutoMapper for that scenario. Reverse mapping can get very complicated very quickly, and unless it's very simple, you can have business logic showing up in mapping configuration.

How does AutoMapper work in C#?

AutoMapper in C# is a library used to map data from one object to another. It acts as a mapper between two objects and transforms one object type into another. It converts the input object of one type to the output object of another type until the latter type follows or maintains the conventions of AutoMapper.


1 Answers

The static version of the CreateMap method was deprecated in 4.2, then removed from the API in version 5.0. Jimmy Bogard talks about this in more detail in this blog post.

The new technique for mapping is non-static, like this (code is from the post):

var config = new MapperConfiguration(cfg => {     cfg.CreateMap<Source, Dest>(); });  IMapper mapper = config.CreateMapper(); var source = new Source(); var dest = mapper.Map<Source, Dest>(source); 
like image 155
Will Ray Avatar answered Oct 16 '22 11:10

Will Ray