【发布时间】:2020-01-13 17:39:45
【问题描述】:
我在我的 asp.net C# 项目中实现了 Auto Mapper,但出现错误:
Mapper 不包含 Initialize 的定义
我试过这个例子Link Here
我已经粘贴了我的代码:
namespace NewsWeb.Web.Infrastructure
{
public class AutomapperWebProfile:Profile
{
public AutomapperWebProfile()
{
CreateMap<DistrictDTO, District>().ReverseMap();
}
public static void Run()
{
Mapper.Initialize(a =>
{
a.AddProfile<AutomapperWebProfile>();
});
}
}
}
在我的 Gobal.asax.cs 文件中:
AutomapperWebProfile.Run();
【问题讨论】:
-
如果您使用的是 v9+,静态 API 已被删除:docs.automapper.org/en/stable/Configuration.html
标签: c# asp.net-mvc automapper