in SampleConsoleApp/ModelFilterExample.cs [72:111]
public static void RunFilteringExample()
{
// Given a model with objects that use "dev", "test" and "prod" schemas
string devPackagePath = GetFilePathInCurrentDirectory("dev.dacpac");
var scripts = SampleScripts;
using (TSqlModel model = new TSqlModel(SqlServerVersion.Sql110, new TSqlModelOptions()))
{
AddScriptsToModel(model, scripts);
Console.WriteLine("Saving test scripts to package '"+devPackagePath+"'");
DacPackageExtensions.BuildPackage(devPackagePath, model, new PackageMetadata());
Console.WriteLine("Objects found in original package: '" + devPackagePath + "'");
PrintTablesViewsAndSchemas(model);
}
string productionPackagePath = GetFilePathInCurrentDirectory("production.dacpac");
// When saving a dacpac for deployment to production (filtering to exclude "dev" and "test" schemas)
var schemaFilter = new SchemaBasedFilter("dev", "test");
ModelFilterer modelFilterer = new ModelFilterer(schemaFilter);
Console.WriteLine("Creating filtered 'production' package: '"+productionPackagePath+"'");
modelFilterer.CreateFilteredDacpac(devPackagePath, productionPackagePath);
// Then expect only the "prod" schema objects to remain in the new package
using (TSqlModel filteredModel = new TSqlModel(productionPackagePath))
{
Console.WriteLine("Objects found in filtered package: '" + productionPackagePath + "'");
PrintTablesViewsAndSchemas(filteredModel);
}
// If we publish the dacpac to a database, we can see that only the production schema is
// present (debug into this method or view the console output listing only production elements)
PublishProductionDacpacAndVerifyContents(productionPackagePath);
}