Automapper IList - Body signature and declaration in method implementation do not match

I have this mapping defined at my application level:

public IList<ProfessionDTO> GetAllProfessions() { IList<Profession> professions = _professionRepository.GetAll(); Mapper.CreateMap<Profession, ProfessionDTO>(); Mapper.CreateMap<IList<Profession>, IList<ProfessionDTO>>(); IList<ProfessionDTO> professionsDto = Mapper.Map<IList<Profession>, IList<ProfessionDTO>>(professions); return professionsDto; } 

Suffix

  public class Profession { private int _id; private string _name; private Profession(){} // required by nHibernate public Profession(int id, string name) { ParameterValidator.NotNull(id, "id is required."); ParameterValidator.NotNull(name, "name is required."); _id = id; _name = name; } public string Name { get { return _name; } } public int Id { get { return _id; } } } 

Profession DTO:

 public class ProfessionDTO { public int Id { get; set; } public string Name { get; set; } } 

When executing GetAllProfessions, I get this error:

The body signature and declaration in the implementation of the method do not match.

Any idea why this is happening?

I just changed the entire IList to List. Now I am not getting an exception, but the list of 27 Profession objects that are retrieved is mapped to 0 from ProfessionDTO.

+6
source share
3 answers

I feel stupid when I answer my question.

I do not need this line:

 Mapper.CreateMap<IList<Profession>, IList<ProfessionDTO>>(); 

Auomapper now works great!

+12
source

You have no settings for your Id and Name attribute in your profession class.

0
source

The indicated answer seems to be wrong; Correctly this should be:

 Mapper.CreateMap<Profession, ProfessionDTO>(); 
0
source

Source: https://habr.com/ru/post/906193/


All Articles