Writing mapping method is machine job. Do not waste your time, let Mapster do it.
PM> Install-Package Mapster
Mapster creates the destination object and maps values to it.
var destObject = sourceObject.Adapt<TDestination>();
You make the object, Mapster maps to the object.
TDestination destObject = new TDestination();
destObject = sourceObject.Adapt(destObject);
Mapster also provides extensions to map queryables.
using (MyDbContext context = new MyDbContext())
{
// Build a Select Expression from DTO
var destinations = context.Sources.ProjectToType<Destination>().ToList();
// Versus creating by hand:
var destinations = context.Sources.Select(c => new Destination(){
Id = p.Id,
Name = p.Name,
Surname = p.Surname,
....
})
.ToList();
}
Don't let other libraries slow you down, raw Mapster performance is at least 2.5 times faster!
And you can boost another 1.3 - 4.0 times faster with FastExpressionCompiler!
Step-into debugging now working in .NET Core!!!