Let’s say you have a mapping between a DTO and an entity. Let’s say that the DTO contains some property that you do not want to be mapped to the entity. How can I tell Automapper to not map this property? I know that you can tell Automapper to not map a destination property. However, that will not help me, as I want to tell Automapper to not map a source property. Here is an example:
public class MyDto
{
int A { get; set; }
int B { get; set; }
int DoNotMapMeToTheEntity { get; set; }
}
public class MyEntity
{
int A { get; set; }
int B { get; set; }
}
As you can see, I do not want Automapper to map DoNotMapMeToTheEntity
to MyEntity
. Now, you might say that, since DoNotMapMeToTheEntity
does not exist in MyEntity
, Automapper will not map it, so I have nothing to worry about. But what if in the future someone adds DoNotMapMeToTheEntity
to MyEntity
. Now Automapper will map it, which I don’t want.
I looked for an option to ignore a source property, but could not find it.
user23278799 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.