Framework 4.5 M> Install-Package AutoMapper -Version 7.0.1 Application_Start //初始化配置AutoMapper AutoMapper.Mapper.Initialize((cfg) => { cfg.AddProfile<MapperConfiguration>(); }); public class MapperConfiguration : Profile { public MapperConfiguration() { CreateMap<model1, model2>() .ForMember(dto => dto.Update_By, options => options.MapFrom(u => u.Name)) .ForMember(dto => dto.Id, opt => opt.Ignore()); } } using AutoMapper; var userModel = Mapper.Map<model2>(model1); var dd = Mapper.Map<List<model1>, List<model2>>(e);
.ForMember(dto => dto.STATUS, options => options.MapFrom(u => (EnumStatus)u.STATUS))
.ForMember(dto => dto.enSTATUS, options => options.MapFrom(u =>( (EnumStatus)u.STATUS).ToString()))
.ForMember(dto => dto.strSTATUS, options => options.MapFrom(u => ((EnumStatus)u.STATUS).GetDescription())); 枚举用法