标签:
在项目中加入AutoMapper
1、编写 影射
//DTO(Dto):数据传输对象,和ViewModel同样的功能 public class DtoMappers { //注册Mapper:在Global.asax中注册 public static void MapperRegister() { Mapper.CreateMap<tbMemberInfo, MemberInfoView>(); Mapper.CreateMap<MemberInfoView, tbMemberInfo>(); Mapper.CreateMap<tbAllyGrade, AllyGradeView>(); Mapper.CreateMap<AllyGradeView, tbAllyGrade>(); Mapper.CreateMap<tbServiceCenterInfo, ServiceCenterInfoView>(); Mapper.CreateMap<ServiceCenterInfoView, tbServiceCenterInfo>(); } }
2、注册影射:
DtoMappers.MapperRegister();
3、使用:
public static tbMemberInfo ConvertViewToModel(MemberInfoView view) { tbMemberInfo model = Mapper.Map<tbMemberInfo>(view); return model; }
相关资料:
使用 AutoMapper 映射 IDataReader、DataSet、DataTable 到实体类
标签:
原文地址:http://www.cnblogs.com/tider1999/p/4504576.html