Comments (12)
@cryo75 Hi, thanks for writing,
Yes, this is the next thing I'm going to work on. Hope to have it ready for January.
Help on testing and so is very appreciated!
from detached-mapper.
started working on profiles!
a big difference between GraphDiff and Detached.Mappers is that the last one works with static compiled expression trees
so there is no way to dinamically evaluate if a property is going to be included or not and what's the type in runtime, without loosing a lot of performance and other features
profiles allows to create a different mapper for each scenario and decide what is going to be included or not, or whats an association or composition.
please take a look at this
you may do something like this to mimic the sample you sent:
`
mapping.AddProfile(MappingProfiles.SaveAll, cfg =>
{
cfg.Type()
.Member(u => u.CustomerType).Association()
.Member(u => u.Title).Association();
cfg.Type<Address>()
.Member(u => u.Title).Association()
.Member(u => u.PostCode).Association();
});
`
I need to add more samples and maybe extension methods to make it easier and more similar to what you are asking for...
(also tests and/or extensions are very welcome if you want to push something to the repo)
have a nice weekend!
from detached-mapper.
My example above shows how I save the customer entity. The PostCode
is used as association in Address
. Here is how I save the postcode itself:
var updated = ((DbContext)dataContext).UpdateGraph<PostCode>
(entity, map => map.AssociatedEntity(x => x.County)
.AssociatedEntity(x => x.State)
.AssociatedEntity(x => x.Country)
);
So if I upgrade to Detached I will need to have add a profile in each and every store, so when saving the customer and will have the postcode as association without its own associations. And when I save the postcode it will have its associations as show above. Is this so?
from detached-mapper.
Yup, you may have an enum to use as a key (key is Object so you can pass anything to it):
enum SaveMode { Create, Update }
then configure
.UseMapping(mapping => { mapping.AddProfile(SaveMode.Update, cfg => { cfg.Type<PostCode>() .ExcludeAll() .Member(u => u.Id).Include() // Detached won't work without an Id to compare by. .Member(u => u.Country).Include().Association() // include Country and mark it as association. .Member(u => u.State).Include().Association() // include State and mark it as association. });
finally map:
dbContext.Map<PostCode>(SaveMode.Update, new { ....)
maybe I can make Association to also call Include to simplify...
it was a quick implementation... needs more feedback
from detached-mapper.
What is the mapping
instance and how do I pass it on to my repository classes?
In which namespace is the MappingProfiles
found?
from detached-mapper.
.UseMapping is new in 6.4.0, it's the replacement of UseDetached that supports profiles.
Profiles (for now) must be created when the dbcontext is configured.
from detached-mapper.
Working on new Wiki to explain everything, but will take some time
from detached-mapper.
from detached-mapper.
No problem. Started porting the entities and mappings to EF7 before adding Detached stuff.
from detached-mapper.
Sure, I'll add or help you to add missing features that you need
from detached-mapper.
It is also important to remember that the profile will be used for loading the entity and all its associations and compositions so that its added to the change tracker before the mapping/diff is done, and before saving.
from detached-mapper.
Can't find any task for me here right now. Please reopen if you need anything.
from detached-mapper.
Related Issues (20)
- Complex properties of entity (Owned entities) cannot be used with EFcore mapper HOT 3
- Issue with ComplexType when using EFCore 8.0 HOT 2
- Map keys to entities and vice versa HOT 1
- [NotMapped] Attribute causes a cast error HOT 2
- Use Alternate Keys (Business Keys) to connect disconnected graph as the primary keys are not part of DTO/Disconnected Entity.
- [NotMapped] Attribut
- Exception creating map on static property HOT 1
- Mapping EF child collection of entities with Identity HOT 5
- Upon inserting entities return the newly seeded values for primary keys HOT 3
- lncrease the verbosity of mapping errors HOT 1
- context disposed in MapAsync HOT 3
- No factory for Optional<Guid?> -> Guid HOT 13
- Map a collection of DTOs to entities HOT 4
- Invalid cast when mapping List<T> to Collection<T> (or any derived Collection) HOT 4
- Ignore Data Annotation HOT 5
- GraphQL and Detached mapper HOT 7
- Aggregation doesn't seem to work properly HOT 10
- Prerelease .Net 8 HOT 5
- Updating a composite collection removes one entry HOT 5
- MapperException: Can't find a concrete type for abstract type or interface HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from detached-mapper.