I am using DacFX to compare and create a script between to SQL Server databases.
After running the compare I go over the changes and exclude some due to internal functionality.
After I finish excluding the objects I run SchemaComparisonResult.GetErrors()
and print out the warnings and errors.
Some of the errors are for objects that were excluded and I don't want to display them as they are no longer relevant.
Is there a way to do that without going over the content of the message as messages might vary and I can't reference all of the in my code
Edit:
I tried doing exclude in 2 ways:
Before running compare:
List<TSqlObject> sourceModel = TSqlModel.LoadFromDatabase(sourceConnectionStringBuilder.ConnectionString).GetObjects(DacQueryScopes.UserDefined).ToList();
List<TSqlObject> targetModel = TSqlModel.LoadFromDatabase(targetConnectionStringBuilder.ConnectionString).GetObjects(DacQueryScopes.UserDefined).ToList();
TSqlObject sourceObject;
TSqlObject targetObject;
foreach (var exclude in preExcludeProp)
{
sourceObject = sourceModel.FirstOrDefault(o => string.Join(".", o.Name.Parts) == exclude.ToString());
targetObject = targetModel.FirstOrDefault(o => string.Join(".", o.Name.Parts) == exclude.ToString());
if (sourceObject != null)
{
comparison.ExcludedSourceObjects.Add(new SchemaComparisonExcludedObjectId(sourceObject.ObjectType, new ObjectIdentifier(sourceObject.Name.Parts.ToArray())));
}
if (targetObject != null)
{
comparison.ExcludedTargetObjects.Add(new SchemaComparisonExcludedObjectId(targetObject.ObjectType, new ObjectIdentifier(targetObject.Name.Parts.ToArray())));
}
}
After running compare:
foreach (SchemaDifference diff in results.Differences)
{
string name = string.Join(".", (diff.SourceObject ?? diff.TargetObject).Name.Parts);
if (postExcludeProp.Contains(name))
{
results.Exclude(diff);
}
}
Both had the same results
Compare: SchemaComparisonResult results = comparison.Compare();
Getting the errors: results.GetErrors()