entity-framework-6 - Automapper 导致错误 : missing type map configuration or unsupported mapping

标签 entity-framework-6 nuget-package automapper-3

我是 Automapper 的新手。

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

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

以下是给我异常(exception)的 Manager 库的声明:

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

异常如下:

Missing type map configuration or unsupported mapping.

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



在 EF 上的 select/where 查询的情况下,它正在工作并且能够使用映射
.Project().To<TReturn>()

我写了一个 Autoconfiguration.cs文件如下:
public static class AutoMapperConfiguration
{
    public static void Configure()
    {
        ConfigureStudentMasterMaps();
    }

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

笔记:

两个实体 - StudentMaster (模型)实体和 StudentDTO具有相同的属性。

请指导我如何解决这个问题。

谢谢你

最佳答案

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

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

你必须添加
Mapper.CreateMap<studentDTO, StudentMaster>();

映射配置调用后
Mapper.AssertConfigurationIsValid();

关于entity-framework-6 - Automapper 导致错误 : missing type map configuration or unsupported mapping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24645746/

相关文章:

c# - AutoMapper-从ViewModel映射回DTO时,subObject保持为空

c# - 应用程序启动时自动在服务器上创建数据库

nuget - NuGet 包被声明为可用于生产后,如何重新打包它们?

Azure Function Nuget 缓存还原失败,错误代码为 "The user name or password is incorrect."

xamarin - 更新 Nuget 导致异常未处理 : System. TypeLoadException

c# - 使用 DeploymentItem 属性的 AutoMapper 单元测试不起作用 - PlatformNotSupportedException

c# - 自动映射器 : passing parameter to Map method

sql-server - 创建临时表并同时存储执行命令的结果

c# - Entity Framework - 所有列均无效

c# - Entity Framework 代码优先 Fluent API