自动映射导致错误:缺少类型映射配置或不支持的映射

use*_*357 5 nuget-package entity-framework-6 automapper-3

我是Automapper的新手.

我已将Nuget包 - Automapper添加到我的Manager(BLL)和DAL层.

现在,下面是相关的东西:

以下是管理器库的声明,它给了我例外:

this.dataRepository.Update(Mapper.Map<StudentMaster>(studentDTO));
Run Code Online (Sandbox Code Playgroud)

例外情况如下:

缺少类型映射配置或不支持的映射.

映射类型:
studentDTO - >
StudentMaster Admin.App.DTO.studentDTO-> Admin.App.DAL.StudentMaster

如果选择/在EF上查询,它正在工作并能够使用

.Project().To<TReturn>()
Run Code Online (Sandbox Code Playgroud)

我写了一个Autoconfiguration.cs文件如下:

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

    private static void ConfigureStudentMasterMaps()
    {
        Mapper.CreateMap<StudentMaster, studentDTO>();                  
    }
}
Run Code Online (Sandbox Code Playgroud)

注意:

实体 - StudentMaster(模型)实体StudentDTO都具有相同的属性.

请指导我如何解决此问题.

谢谢

bob*_*h75 9

请参阅入门https://github.com/AutoMapper/AutoMapper/wiki/Getting-started

CreateMap<**TSource, TDestination**>()
Run Code Online (Sandbox Code Playgroud)

你必须添加

Mapper.CreateMap<studentDTO, StudentMaster>();
Run Code Online (Sandbox Code Playgroud)

映射配置调用后

Mapper.AssertConfigurationIsValid();
Run Code Online (Sandbox Code Playgroud)