Automapper causing error: missing type map configuration or unsupported mapping

user3711357 picture user3711357 · Jul 9, 2014 · Viewed 21k times · Source

I am new to Automapper.

I have added Nuget package - Automapper into my Manager (BLL) and DAL layer.

Now, below is related stuff:

Below is the statment of Manager library that giving me exception:

this.dataRepository.Update(Mapper.Map<StudentMaster>(studentDTO));

Exception is as follow:

Missing type map configuration or unsupported mapping.

Mapping types:
studentDTO -> StudentMaster
Admin.App.DTO.studentDTO-> Admin.App.DAL.StudentMaster

In case of select/where query on EF, it is working and able to map using

.Project().To<TReturn>()

I wrote an Autoconfiguration.cs file as follows:

public static class AutoMapperConfiguration
{
    public static void Configure()
    {
        ConfigureStudentMasterMaps();
    }

    private static void ConfigureStudentMasterMaps()
    {
        Mapper.CreateMap<StudentMaster, studentDTO>();                  
    }
}

Note:

Both the entity - StudentMaster (model) entity and StudentDTO have the same properties.

Please guide me how I could resolve this issue.

Thank You

Answer

bobah75 picture bobah75 · Jul 9, 2014

See Getting-started https://github.com/AutoMapper/AutoMapper/wiki/Getting-started

CreateMap<**TSource, TDestination**>()

You must add

Mapper.CreateMap<studentDTO, StudentMaster>();

After mapping configuration call

Mapper.AssertConfigurationIsValid();