docs/articles/packages/EF-6-and-EF-Core.md
To install the package for EF 6:
PM> Install-Package Mapster.EF6
To install the package for EF Core:
PM> Install-Package Mapster.EFCore
In EF, objects are tracked, when you copy data from dto to entity containing navigation properties, this package will help finding entity object in navigation properties automatically.
Use EntityFromContext method to define data context.
var poco = db.DomainPoco.Include("Children")
.Where(item => item.Id == dto.Id).FirstOrDefault();
dto.BuildAdapter()
.EntityFromContext(db)
.AdaptTo(poco);
Or like this, if you use mapper instance
_mapper.From(dto)
.EntityFromContext(db)
.AdaptTo(poco);
ProjectToTypeMapster.EFCore also allows you to perform projection from IQueryable source via mapper instance and ProjectToType directly to your DTO type.
var query = db.Customers.Where(...);
_mapper.From(query)
.ProjectToType<Dto>();