我正在创建要使用Automapper的简单MVC应用。我已经安装在我的项目中,像这样配置配置文件:
public class ExportProfile : Profile
{
public ExportProfile()
{
CreateMap<User, UserDto>().ReverseMap();
CreateMap<Export, ExportDto>().ReverseMap();
CreateMap<Local, LocalDto>().ReverseMap();
}
}
然后我想转到:Global.asax
Mapper.Initialize( x => x.AddProfile<ExportProfile>() )
;
然后我得到:'Mapper'不包含'Initialize'的定义
我在做什么错?
Mapper.Initialize( x => x.AddProfile<ExportProfile>() )
已过时。
您可以像在这里一样直接在您的控制器类中使用Mapper:
var config = new MapperConfiguration(cfg => cfg.CreateMap<Customer,CustomerDTO>());
var mapper = config.CreateMapper();
return context.Customers.ToList().Select(mapper.Map<Customer, CustomerDTO>);