AutoMapper.EF6

Posted 吴晓阳

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AutoMapper.EF6相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

VSCode自定义代码片段——CSS选择器

谷歌浏览器调试jsp 引入代码片段,如何调试代码片段中的js

片段和活动之间的核心区别是啥?哪些代码可以写成片段?

VSCode自定义代码片段——.vue文件的模板

VSCode自定义代码片段6——CSS选择器

VSCode自定义代码片段——声明函数