2.4. Customizing Database Schema tree
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, in accordance with subject areas or with some other characteristics. Other users wanted to keep objects grouped by physical database structure, but to add own folder for saving frequently used objects or sub-queries there (in a form of virtual objects). It's now easy to implement such wishes without programmatic customization of internal database schema tree or replacing it with your own tree.
Metadata Structure object can be accessed via the QueryBuilder.MetadataStructure property. By default it's responsible for grouping of objects in the tree. You may adjust database objects grouping in the Database Schema Tree by means of the QueryBuilder.MetadataStructureOptions group of properties. However, you can easily re-arrange objects in this structure programmatically or by means of 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 with 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 appropriate node in the Database Schema Tree to browse objects of appropriate namespace.
Dynamic node is actually a node which holds a Metadata Filter. Addition of dynamic node into the Metadata Structure leads to inclusion of all objects (meeting the filter conditions) from the Metadata Container into 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. Filter is a dynamic node. You can learn more about metadata filters here.
There are two scenarios of filling Metadata Structure node programmatically:
a) set the AllowChildAutoItems property of particular node to false and populate it with child items by yourself;
b) set the AllowChildAutoItems property to true and link it with 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. If you want 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).
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.