相关疑难解决方法(0)

启动时没有加载自动映射配置文件?

我正在使用:

  • AutoMapper 6.1.1
  • AutoMapper.Extensions.Microsoft.DependencyInjection 3.0.1

似乎我的配置文件没有被加载,每次我调用mapper.map我得到AutoMapper.AutoMapperMappingException:'缺少类型映射配置或不支持的映射.

这是我的Startup.cs类的ConfigureServices方法

 // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();

        //register automapper

        services.AddAutoMapper();
        .
        .
    }
Run Code Online (Sandbox Code Playgroud)

在另一个名为xxxMappings的项目中,我有我的映射配置文件.示例类

public class StatusMappingProfile : Profile
{
    public StatusMappingProfile()
    {
        CreateMap<Status, StatusDTO>()
         .ForMember(t => t.Id, s => s.MapFrom(d => d.Id))
         .ForMember(t => t.Title, s => s.MapFrom(d => d.Name))
         .ForMember(t => t.Color, s => s.MapFrom(d => d.Color));

    }

    public override string ProfileName
    {
        get …
Run Code Online (Sandbox Code Playgroud)

c# automapper asp.net-core-2.0

8
推荐指数
2
解决办法
3328
查看次数

标签 统计

asp.net-core-2.0 ×1

automapper ×1

c# ×1