标签:automapper
紧接上文autoMapper基本应用,下面说说他的其他应用场景
1、IDataReader映射至实体类
using (System.Data.IDataReader reader =basicDataBase.ExecuteReader(command)) { if (reader.Read()) { return AutoMapper.Mapper.DynamicMap<BlogConfig>(reader); }2、列表类型之间的映射,比如:源类型List<OnClass>,目标类型List<TimeTable>
AutoMapper.Mapper.CreateMap<OnClass,TimeTable>(); var timetablelist = AutoMapper.Mapper.Map<List<OnClass >, List<TimeTable >>(onclass );3、在映射时为目标实例的属性指定值
<span style="font-size:14px;"> var timetablelist = new TimeTable(); AutoMapper.Mapper.CreateMap<OnClass ,TimeTable >().ForMember(dto => dto.OnClassName, opt => opt.UseValue(onclass ));</span>不知道这两篇博客是不是让你学习到一点它的好处,如果还没体会到,敲个demo吧~~
标签:automapper
原文地址:http://blog.csdn.net/wangdan199112/article/details/42298761