-
Notifications
You must be signed in to change notification settings - Fork 406
EF 6 & EF Core
chaowlert edited this page Oct 23, 2020
·
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 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