Library to compare two entity object graphs detecting changes
$ dotnet add package EntityChangeLibrary to compare two entity object graphs detecting changes
The EntityChange library is available on nuget.org via package name EntityChange.
To install EntityChange, run the following command in the Package Manager Console
PM> Install-Package EntityChange
More information about NuGet package available at https://nuget.org/packages/EntityChange
Configure the Contact properties and collections.
EntityChange.Configuration.Default.Configure(config => config
.Entity<Contact>(e =>
{
// set the FirstName display name
e.Property(p => p.FirstName).Display("First Name");
// compare the Roles collection by string equality
e.Collection(p => p.Roles)
.CollectionComparison(CollectionComparison.ObjectEquality)
.ElementEquality(StringEquality.OrdinalIgnoreCase);
// set how to format the EmailAddress entity as a string
e.Collection(p => p.EmailAddresses).ElementFormatter(v =>
{
var address = v as EmailAddress;
return address?.Address;
});
})
.Entity<EmailAddress>(e =>
{
e.Property(p => p.Address).Display("Email Address");
})
);
Compare to Contact entities
// create comparer using default configuration
var comparer = new EntityComparer();
// compare original and current instances generating change list
var changes = comparer.Compare(original, current).ToList();Sample output from the MarkdownFormatter
OUTPUT
Administrator from RolesEmail Address from user@Personal.com to user@gmail.comuser@home.com to Email AddressesStatus from New to VerifiedUpdated from 5/17/2016 8:51:59 PM to 5/17/2016 8:52:00 PMZip from 10026 to 10027Number from 888-555-1212 to 800-555-1212Blah to CategoriesData from 1 to 2Data from ./home to ./path