.net core 将实体映射到AutoMapper中的DTO时出错

.net core 将实体映射到AutoMapper中的DTO时出错,.net-core,automapper,.net Core,Automapper,我已经浏览了谷歌和这里的一些帖子,但我不明白为什么我的Automapper设置映射了一些类,而不是其他类。我使用的是.NETCore3.1和Automapper10.0.0 下面是我的实现 FactoryOLTPSystemsEntity:实体类FactoryOltpSystems:域类DTO 这些类本质上是相同的,具有相同的属性,除了它们属于不同的名称空间之外没有任何变化 服务注册 services.AddAutoMapperAppDomain.CurrentDomain.GetAssembl

我已经浏览了谷歌和这里的一些帖子,但我不明白为什么我的Automapper设置映射了一些类,而不是其他类。我使用的是.NETCore3.1和Automapper10.0.0

下面是我的实现

FactoryOLTPSystemsEntity:实体类FactoryOltpSystems:域类DTO

这些类本质上是相同的,具有相同的属性,除了它们属于不同的名称空间之外没有任何变化

服务注册 services.AddAutoMapperAppDomain.CurrentDomain.GetAssemblys

我的映射类

            //This works perfectly fine 
            CreateMap<Routes, RoutesEntity>()
                .ForMember(dest => dest.integration_id,
                opt => opt.MapFrom(src => Convert.ToString(src.route_id)))
                .ForMember(dest => dest.line_no,
                opt => opt.MapFrom(src => int.Parse(src.dos_line_no.ToString())))
                .ForMember(dest => dest.sub_part_import_src,
                opt => opt.MapFrom(src => double.Parse(src.subimport_path)))
                 .ForMember(dest => dest.dgs_server_id,
                opt => opt.Ignore());

            //This doesnt
            CreateMap<FactoryOLTPSystemsEntity, FactoryOLTPSystems>().ReverseMap();

我不确定我是否遗漏了什么。任何帮助都将不胜感激。干杯

不知道为什么,但这起作用了,而不是

services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
我使用下面的代码在ConfigureService方法中注册AutoMapper

 var mapperConfig = new MapperConfiguration(mc =>
                    {
                        mc.AddProfile(new MappingConfig());
                    });

@LucianBargaoanu,我也在做同样的事情,但它只适用于某些课程,而不适用于其他课程。从零开始,按照文档中的内容做一个例子。我相信它会起作用的。
 var mapperConfig = new MapperConfiguration(mc =>
                    {
                        mc.AddProfile(new MappingConfig());
                    });