Metadata Structure was introduced at the instance of many users wishing to have a possibility to define objects grouping in the Database Schema Tree independently from the physical database schema, by subject areas or with some other characteristics. Other users wanted to keep objects grouped by physical database structure, but to add the special folder for saving frequently used objects or sub-queries there (in the form of virtual objects).
The Metadata Structure object can be accessed via the QueryBuilder.MetadataStructure property. By default, it's responsible for grouping of objects in the tree. You can adjust database objects grouping in the Database Schema Tree using the QueryBuilder.MetadataStructureOptions group of properties. However, you can easily re-arrange objects in this structure programmatically or use the Metadata Editor tool.
Metadata Structure is a tree-like structure consisting of MetadataStructureItem nodes, which can be static or dynamic.
Static node is represented by a single node at the current level of the Database Schema Tree. A static node can represent a definite object of the Metadata Container (by referring to it via the MetadataStructureItem.MetadataItem property), or it can be a folder (a node for grouping other items) if MetadataItem property is null.
The referred object can be not only a database object but also a namespace (a database, a schema, etc. ). A namespace node will generate child nodes automatically to reflect the underlying objects or namespaces (unless it's AllowChildAutoItems property is set to false). For example, you can add Database or Schema node to the Metadata Structure, and the user will be able to expand the appropriate node in the Database Schema Tree to browse objects of the appropriate namespace.
Dynamic node is a node which holds a Metadata Filter. The addition of dynamic node into the Metadata Structure leads to inclusion of all objects (meeting the filter conditions) from the Metadata Container into the appropriate level of the Database Schema Tree.
The Metadata Editor lets add three types of nodes: a folder, an object, and a filter. The first two types are static nodes which mainly differ from each other by the icon. The Filter is a dynamic node. You can learn more about metadata filters here.
There are two scenarios of filling Metadata Structure node programmatically:
- set the AllowChildAutoItems property of the particular node to false and populate it with child items by yourself;
- set the AllowChildAutoItems property to true and link it with the specific item of Metadata Container (MetadataStructureItem.MetadataItem property) to let it be populated with child items automatically.
Anyway, there should be some static nodes below the root, then dynamic or namespace nodes on lower levels. To add a static node below the dynamic one, use the MetadataStructure.ItemAdded event for this purpose (for example, to add the "Favorite" node to each database or schema).
Creating a folder that corresponds to the namespace (database, schema, etc.):
MetadataStructureItem msi = new MetadataStructureItem(); msi.MetadataName = "Database2"; // AQB will search for this name in child items of the Metadata Item referred in the parent Metadata Structure Item msi.AllowChildAutoItems = false; // deny automatic fill for this node to add specific objects further queryBuilder.MetadataStructure.Items.Add(msi);
Creating a custom folder:
MetadataStructureItem folder = new MetadataStructureItem(); folder.Caption = "Favorites"; queryBuilder.MetadataStructure.Items.Add(folder);
Creating a folder with metadata filter:
MetadataStructureItem viewsItem = new MetadataStructureItem(); viewsItem.Caption = "Views"; var filter = viewsItem.MetadataFilter.Add(); filter.ObjectTypes = MetadataType.View; queryBuilder.MetadataStructure.Items.Add(viewsItem);
Adding a particular database object:
MetadataStructureItem tableItem = new MetadataStructureItem(); tableItem.MetadataName = "Northwind.dbo.Orders"; // AQB will search for this full-qualified name in the entire Metadata Container queryBuilder.MetadataStructure.Items.Add(tableItem);
The new Metadata Structure demo project provides the necessary code samples of building custom metadata structure. All available properties and methods of metadata structure objects are documented in detail.