简体   繁体   English

如何合并两个表达式树体?

[英]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. 我正在使用https://github.com/refactorthis/GraphDiff支持合并实体以进行更新。 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. GraphDiff的develop分支为基于属性的映射提供支持。 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. 无需提供映射树的表达式树,而是向模型类中的导航属性添加自定义属性( OwnedAssociated ),然后GraphDiff为您创建映射。 Have a look at GraphDiffs test models for some examples of this. 看一下GraphDiffs测试模型中的一些示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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