The best way I can explain the problem is by using 2 database. The first database holds all the real time data. The second database holds data that we update periodically. I need to determine if a value needs to be updated in the second database. Lets say a field called Occupation. To give few scenarios:
DB1 has value of null, DB 2 has value of null, no update.
DB1 has empty value, DB2 has empty value, no update.
DB1 has empty value, DB2 has null value, no update.
DB1 has null value, DB2 has empty value, no update.
DB1 has a value, DB2 has empty, null or any other value, update.
DB1 has a null, empty, whitespace, DB2 has an actual value, update.
To achieve I wrote a method like this:
if (string.IsNullOrWhiteSpace(db1.Occupation)) db1.Occupation = string.Empty;
if (string.IsNullOrWhiteSpace(db2.Occupation)) db2.Occupation = string.Empty;
if (!db1.Occupation.Equals(db2.Occupation)) return false;
return true;
My question is would there be a built in way to achieve the scenarios I have above? I've looking into if (String.Equals(str1, str2, StringComparison.OrdinalIgnoreCase) and object.Equals(str1, str2) But I don't think those handle the scenarios above due to white space and empty string are 2 different values the way I see it. Maybe I am wrong and this is what this post is to find out if there is a better way.