0

I've been looking for an entity mapping library to save me from writing tons of property mapping code. So I found AutoMapper, AgileMapper and Mapster. As I see it, all help with similarly structured entities. But in my case, my two entities are not even remotely alike.

One property for example:

public class EntityA
{
    public int PropertyA;
}
public class EntityB
{
    public Inner1 inner1;
}
public class Inner1
{
    public Inner2 inner2;
}   
public class Inner2
{
    public double nothingLikeTheOtherPropName
}    

And EntityA.PropertyA maps to Inner2.nothingLikeTheOtherPropName.

So, the question is: Will any entity mapping library help if the two entities are structurally different?

Amit Toren
  • 351
  • 3
  • 13
  • I'm afraid, you have to write mapping code yourself. How any library can guess mapping rules in the posted example? All mappers are mostly convention-based. They can be configured to do something custom, but in your case everything will be custom. So, there won't be any benefits from mapping library. – Dennis Jun 29 '19 at 13:59

1 Answers1

1

AutoMapper can be configured to map the different properties, but there’s no way to automate completely different names. The good thing is that you’d only do it once and everywhere else it’s used will be correct.

Here’s a previous answer

How to specify mapping rule when names of properties differ

  • Yeah that sounds reasonable. So basically it's just a battle of which library does better performance wise. My problem with that is doing it manually takes much less time than AutoMapper. – Amit Toren Jun 29 '19 at 18:38