相关疑难解决方法(0)

AutoMapper从静态API迁移

https://github.com/AutoMapper/AutoMapper/wiki/Migrating-from-static-API

这个改变打破了我的系统.

在更新之前,我使用:

===> Startup.cs

public class Startup
{
    public Startup(IHostingEnvironment env)
    {
    ...
        MyAutoMapperConfiguration.Configure();
    }
}
Run Code Online (Sandbox Code Playgroud)

===> MyAutoMapperConfiguration.cs

public class MyAutoMapperConfiguration
{
    public static void Configure()
    {
        Mapper.Initialize(a =>
        {
            a.AddProfile<AbcMappingProfile>();
            a.AddProfile<XyzMappingProfile>();
            a.AddProfile<QweMappingProfile>();
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

===> AbcMappingProfile.cs

public class AbcMappingProfile : Profile
{
    protected override void Configure()
    {
        Mapper.CreateMap<AbcEditViewModel, Abc>();
        Mapper.CreateMap<Abc, AbcEditViewModel>();
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

错误:

'Mapper.CreateMap()'已过时:'静态API将在5.0版中删除.使用MapperConfiguration实例并根据需要静态存储.使用CreateMapper创建一个映射器实例.

我可以使用Mapper.Map.现在我该如何使用它

c# asp.net automapper

25
推荐指数
3
解决办法
2万
查看次数

标签 统计

asp.net ×1

automapper ×1

c# ×1