I'm trying to save a new object into my db and want to check if it's already in the db before saving.
And I want to check for duplicates by seeing if certain values in the objects are the same.
I have a
class Person
{
public string name
public int age
public string address
public int zipCode
...
...
public string createdBy
public DateTime createdDate
}
i don't care if the createdBy and CreatedDate are the same or not, but i care about all the other values.
Instead of doing a check like this:
if (person1.name == person2.name && person1.age == person2.age &&
person1.address == person2.address && person1.zipCode == person2.zipCode
....... )
{
//it's a duplicate
}
I am wondering if there's something like:
if (person1 == person2 [ignore createdBy && createdDate] )
{
//it's a duplicate
}
EDIT: I have added more properties as an example because my object has about 15 properties total and I only want to compare on 13 properties instead of all 15. I know that manually checking every single property is an option but I am wondering if there is a way to compare the object minus 2 or 3 properties since that would be easier than comparing on 13 properties.