Missing type map configuration or unsupported mapping error in Automapper

I am using Automapper

to map one model to a second model that has multiple rows with the same name as the first model. I am getting this inner exception

Missing map type configuration or unsupported mapping.
   Display types: Bed -> Model1.Bed Bed -> Model2.Bed

This is a compressed 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 be doing something about the mapping of the Bed class even though they both refer to the same method? Also is there a way to copy data from one model to another in this scenario other than manually or using Automapper?

EDIT 1: I'm pretty sure the error is related to this mapping. I removed it and all other fields were fine and there were no exceptions. But I'm not sure how should I make the Bed → Bed binding.

EDIT 2: This link seems to have the same problem and they say this is a possible error and this seems to have an answer, although I'm not sure how I can adapt it to my situation.

+3


source to share


1 answer


It seems like the auto-carper is having trouble figuring out how to match the Bed. I would try the following:

config = new MapperConfiguration(cfg => { 

     cfg.CreateMap<Model1, Model2>(); 
     cfg.CreateMap<Bed, Bed>();

});

      



Although it seems strange what would be necessary ...

+2


source







All Articles