https://blog.csdn.net/yzj_xiaoyue/article/details/62419152
实体映射
var list = new List<tb_article>();
using (dataContext = new EPDbContext())
{
list = dataContext.tb_article.Take(10).ToList();
}
AutoMapper.Mapper.CreateMap<tb_article, tb_articleDto>()
.ForMember(d => d.title, opt =>
{
opt.MapFrom(s => s.author);
}).ForMember(d => d.id, opt =>
{
opt.MapFrom(s => s.status);
}); ;
var small_list=AutoMapper.Mapper.Map<List<tb_article>,List<tb_articleDto>> (list);
EF 查询 前 进行 实体映射:提高 效率:
var list = new List<tb_articleDto>();
using (dataContext = new EPDbContext())
{
string str_list = dataContext.tb_article.Take(10).Project().To<tb_articleDto>().ToString();
}