我是 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/