简体   繁体   中英

How do I combine two expression tree bodies?

If I have:

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

and

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)

and:

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 https://github.com/refactorthis/GraphDiff 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM