Assume the following class:
public class MyEntity
{
public string FirstName;
public string LastName;
}
I would like to use AutoMapper
to compare two MyEntity
objects, and create a new MyEntity
object that contains only the differences between the two objects. Properties that are equal will result a null
value in the new object.
for example, the I would like the following lines:
MyEntity entity1 = new MyEntity() { FirstName = "Jon", LastName = "Doh" };
MyEntity entity2 = new MyEntity() { FirstName = "Jon", LastName = "The Great" };
MyEntity diffEntity = Mapper.Map...; // Compare the two objects using AutoMapper
to result with the following diffEntity
values:
{
FirstName: null,
LastName: "The Great"
}
The final goal is to enable a client mobile application to send a DTO that contains only the changes made to an entity, to a ASP.NET MVC WebAPI server application.
Please assume that I have many classes of entities which requires the same handling, and I would like to avoid manually writing property names for each comparison.
Is it possible?