Efficiently finding differences
pprewett
Posts: 2
Hello –
I’m using SQL Compare in my unit testing to compare a newly created database with a snapshot of the expected schema. I'm not interested in actually synchronizing the databases... only finding out if their schema is identical.
While I have it working, I’m not sure if this is the ‘correct’ way to do it. It doesn’t seem right.
It seems as if there would be a better way to do this, rather than having to loop through all the “differences†and check to see if they are equal or not. The first way I expected was simply this:
Assert.IsTrue(differences.Count == 0);
But I guess the Differences object actually has an item for every mapping in the comparison, whether or not they’re actually different.
Would this be the suggested way to use the API to do what I’m trying to do, or is there a more efficient or advisable way?
Thanks,
Paul
I’m using SQL Compare in my unit testing to compare a newly created database with a snapshot of the expected schema. I'm not interested in actually synchronizing the databases... only finding out if their schema is identical.
While I have it working, I’m not sure if this is the ‘correct’ way to do it. It doesn’t seem right.
Differences differences = actualDb.CompareWith(expectedDb, Options.Default); bool databasesAreIdentical = true; foreach(Difference difference in differences) { databasesAreIdentical = difference.Type == DifferenceType.Equal; if (!databasesAreIdentical) { break; }//if }//if Assert.IsTrue(databasesAreIdentical);
It seems as if there would be a better way to do this, rather than having to loop through all the “differences†and check to see if they are equal or not. The first way I expected was simply this:
Assert.IsTrue(differences.Count == 0);
But I guess the Differences object actually has an item for every mapping in the comparison, whether or not they’re actually different.
Would this be the suggested way to use the API to do what I’m trying to do, or is there a more efficient or advisable way?
Thanks,
Paul
Comments
Your way of checking for differences between the compared databases is the best way as far as I can tell. The Differences collection has a bit of a deceptive name: a 'Difference' can actually be identical or only in the first database or only in the second database!