I have two object of the class Profile
and I want to compare it to get the difference. To explain better:
public partial class Profile
{
public long Id { get; set; }
public long VisitorId { get; set; }
public string Description { get; set; }
public long Age { get; set; }
public DateTime? LastUpdate { get; set;}
}
I want to know in my method the differences between the object oldProfile
and newProfile
to make a changelog.
For example, if oldProfile
had Age = 10
and Description = "old"
and newProfile
has Age = 11
and Description = "new"
, I would now this differences to make two different insert in my database:
public void PostChangelogProfileDetail(Profile oldProfile, Profile newProfile)
{
ProfileDetailChangeLog profileDetailChangeLog = new ProfileDetailChangeLog();
//COMPARE oldProfile AND newProfile
foreach ( //difference resulted in the compare)
{
profileDetailChangeLog.VisitorId = newProfile.VisitorId;
profileDetailChangeLog.ModifiedRecord = //name of the attribute modified (Age, Description, etc...)
_profileDetailChangeLog.Create(profileDetailChangeLog);
}
}