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 exception
Missing type map configuration or unsupported mapping.
Mapping types: Bed -> Bed Model1.Bed -> Model2.Bed
This 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.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With