Missing type map configuration or unsupported mapping error in Automapper
It seems like auto mapper is having trouble determining how to map Bed. I would try the following:
config = new MapperConfiguration(cfg => {
cfg.CreateMap<Model1, Model2>();
cfg.CreateMap<Bed, Bed>();
});
Although it seems odd that would be necessary...
The_Outsider
Writing C# code for 6 years now, trying to give back to the community which has helped me grow.Professionally working on C#, ASP.Net MVC5, SQL Server, Entity Framework 6. Learning and exploring about Node.JS,React and Image Recognition in my personal time.
Updated on July 18, 2022Comments
-
The_Outsider almost 2 years
I am using an
Automapper
to map one model to second model which has some rows with the same name as the first model. I am getting this inner exceptionMissing type map configuration or unsupported mapping.
Mapping types: Bed -> Bed Model1.Bed -> Model2.BedThis is the condensed version of the code.
Model 1
public class Model1 { public Guid Id { get; set; } public string Name { get; set; } public IEnumerable<Bed> Beds { get; set; } public IEnumerable<Bed> Beds1 { get; set; } public string Status {get; set;} public string Notes {get; set;} } public class Model2 { public Guid Id { get; set; } public string Name { get; set; } public IEnumerable<Bed> Beds { get; set; } public IEnumerable<Bed> Beds1 { get; set; } } public class Bed { public Guid Id { get; set; } public Guid TypeId { get; set; } public string Type { get; set; } public string Notes { get; set; } public DateTime? CreatedOn { get; set; } public DateTime? LastUpdatedOn { get; set; } }
Mapping :
MapperConfiguration config = null; config = new MapperConfiguration(cfg => { cfg.CreateMap<Model1, Model2>(); }); IMapper mapper = config.CreateMapper(); var dest = mapper.Map<Model1, Model2>(update);
update is an instance of Model1. Am I missing something? Should I do something with regards to the Bed class mapping even though both reference the same method? Also is there a way to copy data from one model to another in this scenario other than manually doing it or using Automapper?
EDIT 1: I am sure the error is from that mapping. I removed it and all the other fields were fine and there was no exception. But I am not sure how I should do the Bed -> Bed binding.
EDIT 2:This link seems to have the same issue and they say it's a possible bug and This one seems to have the answer although I am not sure how I can adapt it to my situation.
-
The_Outsider almost 7 yearsThat was the missing issue. I am not sure why it was needed but it seem to resolve the problem.
-
Zoop almost 7 yearsYeah, seems strange but I'm glad it worked. Good luck!