Art*_*ior 6 .net ilist dto automapper c#-4.0
我在我的应用层中定义了这个映射:
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;
}
Run Code Online (Sandbox Code Playgroud)
Proffesion实体
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; }
}
}
Run Code Online (Sandbox Code Playgroud)
职业DTO:
public class ProfessionDTO
{
public int Id { get; set; }
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
执行GetAllProfessions时出现此错误:
正文签名和方法实现中的声明不匹配.
知道为什么会这样吗?
我刚刚将所有IList更改为List.我现在没有得到例外,但是检索到的27个Profession实体的List被映射到ProfessionDTO的0.
Art*_*ior 12
我觉得很难回答我自己的问题.
我不需要这一行:
Mapper.CreateMap<IList<Profession>, IList<ProfessionDTO>>();
Run Code Online (Sandbox Code Playgroud)
现在Auomapper完美无缺!