How to open the Metadata Container Editor from code?
Active Query Builder has a special facility to work with metadata, i.e. extract the information about a database schema, edit and save it to XML files as well as to customize the tree-like presentation of the schema for end-users.
This editor was primarily made for developers and administrators who are responsible for defining user roles in the application. Even though the editor provides tips of using specific options and reports about errors in SQL expression wherever it is possible, we recommend acquainting users of the effects to which different property settings (Virtual objects, Alternate names) may lead.
The Metadata Container Editor is available for download as a standalone application, and in the WinForms Edition, it also can be called from code in several ways.
Firing Metadata Editor from code
The Standard subscription has the QueryBuilder.EditMetadataContainer static method available while the Professional subscription adds the QueryBuilder.EditMetadataContainerStandalone method.
The EditMetadataContainer method allows editing the content of MetadataContainer and MetadataStructure objects owned by the SQLContext object passed as a first parameter. It can load metadata only from the database connection assigned to the given SQL context. The user is not allowed to establish new connections, either to save and load the content to external files.
The EditMetadataContainerStandalone adds the way to call the Metadata Container Load Wizard which allows establishing new database connections as well as saving and loading metadata and structure to and from XML files.
Both methods require an SQLContext passed as a parameter. It determines the initial SQL syntax, database connection and the content of MetadataContainer and MetadataStructure objects.
Both methods have an overload to accept the MetadataEditorOptions set of options as the second parameter to turn off unwanted options of the editor.
- DisableStructurePane (0x1): Instructs to hide the Metadata Structure Tree. This way the user has only two panels: the content of the MetadataContainer on the left and the properties bar on the right.
- DisableLoadDatabaseButton (0x2): Instructs to hide the "Load Database Schema from Server" button and denies calling the Metadata Loading Wizard.
- DisableVirtualObjects (0x4): Instructs to disable editing of the Expression property to manage virtual objects and fields. Virtual objects can ease the work with queries, but inexperienced users can unintentionally set this property for a real object which will lead to the unexpected change in SQL query generation.
Metadata Loading Wizard
Having the Professional WinForms subscription you can call this wizard from code using the QueryBuilder.ShowMetadataContainerLoadWizard static method. It returns true if closed by the Finish button on the last step, false otherwise.
The wizard let the user establish connections to different database servers, select the needed objects to extract and do the job. To get all types of connections available while calling this wizard from code, you must refer to appropriate MetadataProvider assembly, some of them require third-party database connector assemblies referred.