简体   繁体   English

Automapper是否可以将复杂的源图映射到平面目标,而在目标属性中没有前缀并且没有自定义映射?

[英]Can Automapper map a complex source graph to a flat destination without prefixes in the destination properties and without custom mappings?

Is there a way to get Automapper to map a complex source graph like: 有没有办法让Automapper映射一个复杂的源图,例如:

public class Source {
    public string Name { get; set; }
    public SourceSub Sub { get; set; }
}

public class SourceSub {
    public string ValA { get; set; }
    public string ValB { get; set; }
}

to a flat destination that looks like: 到看起来像这样的平坦目的地:

public class Dest {
    public string Name { get; set; }
    public string ValA { get; set; }
    public string ValB { get; set; }
}

I know something like this will work for a destination: 我知道类似这样的方法适用于目的地:

public class Dest {
    public string Name { get; set; }
    public string SubValA { get; set; }
    public string SubValB { get; set; }
}

However, I am looking for a way to map to the destination without requiring a prefix in the destination properties (for the child class in the source) as long as the names in the child class properties of the source match the destination property names. 但是,我正在寻找一种映射到目标的方式,只要源的子类属性中的名称与目标属性名称匹配,就不需要在目标属性(源中的子类)中添加前缀。 Is there a way to tell Automapper to project properties in a child class of the source to a flat destination class without mapping each individual member? 有没有一种方法可以告诉Automapper在不映射每个成员的情况下将源的子类中的属性投影到平面目标类中?

No, this isn't a supported scenario right now. 不,目前不支持此方案。 We looked at it for a while, but found the naming collision rate too high for our apps, and having the name flattened preserved the full context for where that value came from. 我们看了一会儿,但是发现我们的应用程序的命名冲突率太高,并且将其名称展平保留了该值来自何处的完整上下文。

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

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