Options

Efficiently finding differences

pprewettpprewett Posts: 2
edited August 10, 2007 12:06PM in SQL Toolkit Previous Versions
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.
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

  • Options
    Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hi,

    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!
Sign In or Register to comment.