I use EntityFramework as a DataLayer and DTO to transfer data between layers. I am developing Windows Forms in an N-tier architecture and when trying to map from Entity to DTO in BLL:
public IEnumerable<CategoryDTO> GetCategoriesPaged(int skip, int take, string name) { var categories = unitOfWork.CategoryRepository.GetCategoriesPaged(skip, take, name); var categoriesDTO = Mapper.Map<IEnumerable<Category>, List<CategoryDTO>>(categories); return categoriesDTO; }
I have this error: http://s810.photobucket.com/user/sky3913/media/AutoMapperError.png.html
The error indicates that I do not have a type map configuration or an unsupported display. I registered the mapping using the profile this way at the user interface level:
[STAThread] static void Main() { AutoMapperBusinessConfiguration.Configure(); AutoMapperWindowsConfiguration.Configure(); ... Application.Run(new frmMain()); }
and AutoMapper configuration is in BLL:
public class AutoMapperBusinessConfiguration { public static void Configure() { Mapper.Initialize(cfg => { cfg.AddProfile<EntityToDTOProfile>(); cfg.AddProfile<DTOToEntityProfile>(); }); } } public class EntityToDTOProfile : Profile { public override string ProfileName { get { return "EntityToDTOMappings"; } } protected override void Configure() { Mapper.CreateMap<Category, CategoryDTO>(); } } public class DTOToEntityProfile : Profile { public override string ProfileName { get { return "DTOToEntityMappings"; } } protected override void Configure() { Mapper.CreateMap<CategoryDTO, Category>(); } }
I also have the same error when comparing with DTO on Entity.
category = Mapper.Map<Category>(categoryDTO);
How to solve this?
Willy source share