Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automapper causing error: missing type map configuration or unsupported mapping

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

like image 974
user3711357 Avatar asked Jul 09 '14 05:07

user3711357


2 Answers

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();
like image 160
bobah75 Avatar answered Nov 02 '22 23:11

bobah75


I had a similar problem, I forgot to register in the Global.asax

public class WebApiApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        GlobalConfiguration.Configure(WebApiConfig.Register);


        AutoMapperConfig.RegisterMappings();

    }
}
like image 1
Melqui Franco Avatar answered Nov 02 '22 23:11

Melqui Franco