There are several ways to exclude unwanted objects from the Database Schema View. You can define filters to exclude objects by the name or mask. Another way is to use the Metadata Editor tool to remove unwanted objects from the Metadata Container explicitly.
The Metadata Editor tool can be downloaded from the download page (in the "Additional Downloads" section). When editing is finished, you can save the result to an XML file and then load metadata from this XML file instead of working with the live database connection. Loading metadata from XML file will also reduce a load on your database and web servers (in the case of the ASP.NET Edition).
The third way is to keep the Metadata Container untouched, but use the Metadata Structure presentation layer to customize the Database Schema Tree, but this way you can only hide objects from the tree, not to remove them from the Metadata Container.
Using metadata filters, you can prevent loading of objects with specific names or load objects with specific names only. You can also display only objects of certain types or from specified databases/schemas.
Note that you can also specify metadata filter for a node of the Metadata Structure (MetadataStructureItem.MetadataFilter). You can read more about defining custom metadata structure in this article: Customizing Database Schema Tree structure.
You can specify metadata filters in two ways. It's easier to setup filters in a first way, but using the second way you can create more complex filters.
The simple way to define filters
The QueryBuilder.MetadataLoadingOptions.IncludeFilter lets define a set of visible objects (only the objects which satisfy it will be visible) and the QueryBuilder.MetadataLoadingOptions.ExcludeFilter allows defining a set of objects which should not be visible (the objects that satisfy it will be hidden). You can define both properties, and they will work together just fine.
Both properties are of the SimpleMetadataFilter class which has Names, Schemas and Types fields. Using them you can specify masks for database object and schema names (read the rules of mask definition below), set types of objects to display or hide.
For example, in the result of the following statements execution, the user will see all views from the database, except those which reside in the "dbo" schema.
queryBuilder1.MetadataLoadingOptions.IncludeFilter.Types = [View]; queryBuilder1.MetadataLoadingOptions.ExcludeFilter.Schemas.Add("dbo");
The advanced way to define filters
Metadata Filter is a set of filtration rules. Each rule in the list is represented by the MetadataFilterItem object. An item can define objects to be set excluded or included in the result set according to the Exclude property. Metadata Filter can have multiple exclusion and inclusion items (rules). If Metadata Filter has no inclusion items, the exclusion items will be applied to the whole database schema. If Metadata Filter has some inclusion items, they will constitute a subset of the database schema, to which the exclusion items will be applied.
Each Metadata Filter Item has a mask for each type of metadata items: Server, Database, Schema, Package, Object, and Field. Each mask determines a subset of objects which names match this mask. Those masks act similar to the "LIKE" SQL operator: you can use the percent character (%) to represent any sequence of characters; use the underscore character (_) to represent any single character. The CaseSensitive property determines case sensitivity of masks. The ObjectTypes property determines which object types (Table, View, Synonym, Procedure or Function) will be included or excluded.
You may treat those rules as SQL conditions combined with OR operators in WHERE clause of the SELECT statement that retrieves the list of objects to be loaded to the Metadata Container. Conditions marked with the Exclude flag are prefixed with the NOT operator. The result SQL WHERE clause will look like the following: "([inculsion rule] OR [inclusion rule] OR ...) AND NOT ([exculsion rule] OR [exclusion rule] OR ...)". Masks of one rule are combined with the AND operator.
The following example adds new filter item that excludes objects with names starting with "pre_":
MetadataFilterItem mfi = queryBuilder1.MetadataLoadingOptions.MetadataFilter.Add(); mfi.Exclude = true; mfi.Object = "pre_%"; mfi.CaseSensitive = true;
And the following example adds new filter item that excludes all schemas except the "schema":
MetadataFilterItem mfi = queryBuilder1.MetadataLoadingOptions.MetadataFilter.Add(); mfi.Exclude = false; mfi.Schema = "dbo";
The following sample demonstrates filtration by object type:
MetadataFilterItem metadataFilterItem = queryBuilder1.MetadataLoadingOptions.MetadataFilter.Add(); metadataFilterItem.Exclude = false; metadataFilterItem.ObjectTypes = MetadataType.Table | MetadataType.View; metadataFilterItem.FlagSystem = false; metadataFilterItem.FlagUser = true; queryBuilder1.MetadataContainer.Items.Clear(); queryBuilder1.InitializeDatabaseSchemaTree();