Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,25 @@ | ||
# AutoMapper.EF6 | ||
Extensions for AutoMapper and EF6 | ||
|
||
This contains some useful extensions I've 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). |