AutoMapper
AutoMapper
1.通过NuGet添加引用
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
2.新增AutoMapperConfig类处理映射配置
/// <summary> /// 映射配置 /// </summary> public class AutoMapperConfig { public static void RegisterMappings() { Mapper.Initialize(cfg => { cfg.CreateMap<City, CityDto>(); cfg.CreateMap<CityDto, City>(); }); } }
3.在Global.asax.cs的Application_Start方法中调用 AutoMapperConfig.RegisterMappings();
4.调用示例
City city = new City(); CityDto dto = AutoMapper.Mapper.Map<CityDto>(city); //将City实体映射到CityDto中

更多精彩