Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automapper IList - Signature of the body and declaration in a method implementation do not match

I have this mapping defined in my Application Layer:

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

Proffesion entity

 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:

Signature of the body and declaration in a method implementation do not match.

Any idea why is it happening?

I have just changed all the IList to List. I don't get the exception now but the List of 27 entities of Profession that is retrieved is mapped to 0 of ProfessionDTO.

like image 460
Artur Kędzior Avatar asked Jan 17 '12 10:01

Artur Kędzior


1 Answers

I feel silly answering my own question.

I don't need this line:

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

Now Auomapper works perfectly!

like image 194
Artur Kędzior Avatar answered Sep 28 '22 08:09

Artur Kędzior