Giter VIP home page Giter VIP logo

Comments (12)

leonardoporro avatar leonardoporro commented on June 5, 2024

@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.

leonardoporro avatar leonardoporro commented on June 5, 2024

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.

cryo75 avatar cryo75 commented on June 5, 2024

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.

leonardoporro avatar leonardoporro commented on June 5, 2024

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.

cryo75 avatar cryo75 commented on June 5, 2024

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.

leonardoporro avatar leonardoporro commented on June 5, 2024

.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.

leonardoporro avatar leonardoporro commented on June 5, 2024

Working on new Wiki to explain everything, but will take some time

from detached-mapper.

leonardoporro avatar leonardoporro commented on June 5, 2024

from detached-mapper.

cryo75 avatar cryo75 commented on June 5, 2024

No problem. Started porting the entities and mappings to EF7 before adding Detached stuff.

from detached-mapper.

leonardoporro avatar leonardoporro commented on June 5, 2024

Sure, I'll add or help you to add missing features that you need

from detached-mapper.

cryo75 avatar cryo75 commented on June 5, 2024

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.

leonardoporro avatar leonardoporro commented on June 5, 2024

Can't find any task for me here right now. Please reopen if you need anything.

from detached-mapper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.