I have two lists List<T> existingValues
& List<T> newValues
foreach item in newvalues
I check if it exists in existingValues
(I check existence of value based on primary key value), if it does not exist i will add it to existingValues
.
Now if value already exists in existingValues
I want to check if any columns values are diffenrent and if they are different I would like to update them, how can I do this?
foreach(var item in newvalues)
{
if(!existingValues.Any(x => x.PrimaryKeyVal == item.PrimaryKeyVal))
{
newValues.Add(item);
}
if (existingValues.Any(x => x.PrimaryKeyVal == item.PrimaryKeyVal))
{
//do something here to check if both rows are same, if not update the row with new values
}
}