【发布时间】:2019-11-11 01:39:57
【问题描述】:
我一直在寻找一个实体映射库来避免我编写大量的属性映射代码。所以我找到了 AutoMapper、AgileMapper 和 Mapster。正如我所看到的,所有这些都有助于结构相似的实体。但就我而言,我的两个实体甚至完全不一样。
一个属性例如:
public class EntityA
{
public int PropertyA;
}
public class EntityB
{
public Inner1 inner1;
}
public class Inner1
{
public Inner2 inner2;
}
public class Inner2
{
public double nothingLikeTheOtherPropName
}
EntityA.PropertyA 映射到 Inner2.nothingLikeTheOtherPropName。
所以,问题是:如果两个实体在结构上不同,任何实体映射库都会有所帮助吗?
【问题讨论】:
-
恐怕你得自己写映射代码。在发布的示例中,任何库如何猜测映射规则?所有映射器大多是基于约定的。它们可以配置为做一些自定义的事情,但在你的情况下,一切都是自定义的。因此,映射库不会有任何好处。
标签: c# mapping automapper