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())); 枚举用法 

  

posted on 2020-07-21 14:38  Aaron_Net  阅读(158)  评论(0编辑  收藏  举报