Excluding Columns to Compare in SqlDataCompare (using API)
srikmr
Posts: 16
Hi,
I'm trying to evalute SqlDataCompare API for our project.
My requirement is like this:
I am writing some test cases to compare data.
I have 2 Databases viz TestDB and ProdDB which have the same structures. I need to compare the Data in Table1 of TestDB with Data in Table1 of ProdDB. In doing so, i need to exclude few columns for comparision. I'm unable to achieve this.
I am able to see this hapening in the Tool, (with the selections), but i need to write code using your API.
Using your API help, i have developed the below code. I'm stuck at the point of comparing two tables from two databases where i can specify the columns to be compared. Could you please give your valueble inputs on this.
For your reference, below is my current code:
Thanks
Srikmr
I'm trying to evalute SqlDataCompare API for our project.
My requirement is like this:
I am writing some test cases to compare data.
I have 2 Databases viz TestDB and ProdDB which have the same structures. I need to compare the Data in Table1 of TestDB with Data in Table1 of ProdDB. In doing so, i need to exclude few columns for comparision. I'm unable to achieve this.
I am able to see this hapening in the Tool, (with the selections), but i need to write code using your API.
Using your API help, i have developed the below code. I'm stuck at the point of comparing two tables from two databases where i can specify the columns to be compared. Could you please give your valueble inputs on this.
For your reference, below is my current code:
Database db1 = new Database(); Database db2 = new Database(); ComparisonSession session = new ComparisonSession(); TableMappings mappings = new TableMappings(); try { db1.RegisterForDataCompare(new ConnectionProperties(".", "TestDB")); db2.RegisterForDataCompare(new ConnectionProperties(".", "ProdDB")); // Create the mappings between a certain table TableMapping tableMapping = (TableMapping)mappings.Join(db1.Tables["[dbo].[Table1]"], db2.Tables["[dbo].[Table1]"]); // Set the custom comparison key for the table tableMapping.MatchingMappings.Clear(); tableMapping.MatchingMappings.Add(tableMapping.FieldMappings["DeviceID"]); tableMapping.RefreshMappingStatus(); mappings.Add(tableMapping); // Set the where clause for the comparison tableMapping.Where = new WhereClause("DeviceType = 'A'"); // TODO: code to set the columns to be excluded // Peform the comparison session.CompareDatabases(db1, db2, mappings); TableDifference difference = session.TableDifferences["[dbo].[Table1]"]; if (difference.DifferencesSummary.DifferenceCount() == 0) Console.WriteLine("Both tables are Same"); else Console.WriteLine("Difference of Tables exist."); } finally { session.Dispose(); db1.Dispose(); db2.Dispose(); }
Thanks
Srikmr
Comments
You can set a mapping's .Include property to set whether or not it will be included in the data comparison: