Automapper causing error: missing type map configuration or unsupported mapping

automapper-3 entity-framework-6 nuget-package

Question

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

1
5
7/9/2014 5:12:46 AM

Accepted Answer

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();
9
7/9/2014 5:22:41 AM

Popular Answer

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();

    }
}


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow