forked from MapsterMapper/Mapster
-
Notifications
You must be signed in to change notification settings - Fork 3
Basic usages
chaowlert edited this page May 27, 2017
·
1 revision
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();
}