码迷,mamicode.com
首页 > 移动开发 > 详细

AutoMapper.EF6

时间:2016-06-25 09:35:14      阅读:904      评论:0      收藏:0      [点我收藏+]

标签:

https://github.com/AutoMapper/AutoMapper.EF6

 

Extensions for AutoMapper and EF6

This contains some useful extensions Ive used with AutoMapper and EF6. Instead of this:

Mapper.CreateMap<Employee, EmployeeDto>()
  .ForMember(d => d.FullName, opt => opt.MapFrom(src => src.FirstName + " " + src.LastName));

var employees = await db.Employees.ProjectTo<EmployeeDto>().ToListAsync();
You can do this instead:

public class Employee {
  [Computed]
  public string FullName { get { return FirstName + " " + LastName; } }
}
Mapper.CreateMap<Employee, EmployeeDto>();

var employees = await db.Employees.ProjectToListAsync<EmployeeDto>();
This package wraps up calling ProjectTo, the DelegateDecompiler Decompile/DecompileAsync methods, and then the LINQ methods to execute the queryable (ToList, ToArray, Single, SingleOrDefault etc).

 

AutoMapper.EF6

标签:

原文地址:http://www.cnblogs.com/shiningrise/p/5615814.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!