I have a collection of some models:
class Person
{
public int Id {get;set;}
public int Age {get;set;}
public string Name {get;set;}
}
var collectionModel = new List<Person>{ ... };
And the DTO collection:
class PersonDto
{
public int Id {get;set;}
public int Age {get;set;}
public string Name {get;set;}
public int RowNumber {get;set;}
}
var collectionDto = new List<PersonDto>{ ... };
So, collectionModelI get from the repository (database), collectionDtoI get from the remote client.
Is there an effective way to compare these collections and “apply changes” (update changed objects, delete nonexistent ones and add new ones) in collectionModelto save it to the database?
An obvious option is to compare collections by hand, update properties, create and delete objects. But this code is repeated.
source
share