How do I combine two expression tree bodies?

c# expression graphdiff lambda linq


If I have:

m => m.OwnedCollection(p => p.Addresses)


m => m.OwnedCollection(p => p.Contacts)

I'd like to combine them to be:

m => m.OwnedCollection(p => p.Addresses).OwnedCollection(p => p.Contacts)

Is there a way of doing this?

I'd also like to be able to combine:

m => m.OwnedCollection(p => p.Contacts)


with => with.AssociatedCollection(p => p.AdvertisementOptions)

to be:

m => m.OwnedCollection(p => p.Contacts, with => with.AssociatedCollection(p => p.AdvertisementOptions))

Is there a way of doing this one as well?

I'm hoping that these are fairly simple requirements but I'm finding it difficult to get to grips with the terminology.

Some background:

I'm using to support merging of entities for updates. The problem is that it expects an expression tree describing the relationships of the enitity to be updated eg.

context.UpdateGraph(company, map => map
    .OwnedCollection(p => p.Contacts, with => with
        .AssociatedCollection(p => p.AdvertisementOptions))
    .OwnedCollection(p => p.Addresses)

Mine needs to be a generic solution, so I need to examine the various one-to-one, one-to-many and many-to-many relationships of my entities type using reflection and convert these to an expression tree.

Any help on my specific questions or general help would be appreciated.

10/1/2014 3:17:50 PM

Accepted Answer

The develop branch of GraphDiff provides support for attribute based mapping. Instead of providing an expression tree mapping your graph, you add custom attributes (Owned or Associated) to the navigation properties in your model classes and GraphDiff creates the mapping for you. Have a look at GraphDiffs test models for some examples of this.

10/26/2014 11:53:38 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow