Excluding columns

Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
edited October 13, 2004 10:07AM in SQL Toolkit Previous Versions
Hi,

Yes, good question. We'll have to do up some articles about that. In the meantime, here are some changes that you can make to the examples.

To change the comparison key, you can specify it in place of table.PrimaryKey.Fields. If you have a unique index called foo:

foreach (Table table in commonTables)
{
settings.Add(new TableComparisonSetting(table.FullyQualifiedName, table.Fields, table.Indexes["foo"].Fields));
}


Changing the collection of columns is a bit more complex. You'd want to create a new enumeration of columns and conditionally add them:

foreach (Table table in commonTables)
{
Fields fc = new Fields();
foreach (Field f in fc)
{
if (f.Name=="bar") fc.Add(f);
}

settings.Add(new TableComparisonSetting(table.FullyQualifiedName, fc, table.Indexes["foo"].Fields));
}

Hopefully this will point you in the right direction!

Comments

  • Thanks. It's a good place to start. I look forward to future articles.
  • I got the generic compare and the exclusion of fieldsworking fine, but I'm a little confused on how to set the properties so I'm working like a one-way replication. I only want to synch differences (onlyin1) and missing, but ignore additional(onlyin2) and equal.

    I believe I want the following command to be run, ultimately:
    SessionSettings sessionSettings = new SessionSettings ();

    comparisonSession.CompareDatabases(db1, db2, tableComparisonSettings, sessionSettings);

    but I'm not sure exactly how to set sessionSettings for IncludeDifferentRecords and IncludeRecordsInOne.
  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hi,

    I'm glad that your project is working out well. What you want to do is set up SessionSettings, which is an enumeration rather than an Object that you can instantiate and use.

    SessionSettings enSettings=SessionSettings.IncludeRecordsInOne | SessionSettings.IncludeDifferentRecords

    ...

    comparisonSession.CompareDatabases(db1, db2, tableComparisonSettings, enSettings);
  • Thanks for the help.
This discussion has been closed.