-
Notifications
You must be signed in to change notification settings - Fork 332
EF 6 & EF Core
chaowlert edited this page Feb 6, 2021
·
4 revisions
For EF 6
PM> Install-Package Mapster.EF6
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 plugin will help finding entity object in navigation properties automatically.
- use Mapster.EFCore version 5.x for EFCore 5.x
- use Mapster.EFCore version 3.x for EFCore 3.x
- use Mapster.EFCore version 1.x for EFCore 2.x
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);
Mapster.EFCore
also allows ProjectToType
from mapper instance.
var query = db.Customers.Where(...);
_mapper.From(query)
.ProjectToType<Dto>();
- Configuration
- Config inheritance
- Config instance
- Config location
- Config validation & compilation
- Config for nested mapping
- Custom member matching logic
- Constructor mapping
- Before & after mapping
- Setting values
- Shallow & merge mapping
- Recursive & object references
- Custom conversion logic
- Inheritance