Active Query Builder support area

how to add a folder to metadatastructure?

Avatar
  • updated
  • Completed
Just like that.

Trying customize web version of Active Query Builder.
I tried:
queryBuilder.MetadataStructure.AllowChildAutoItems = false;
queryBuilder.MetadataStructure.Items.Add(new MetadataStructureItem() { Caption = "Capt"});
queryBuilder.MetadataStructure.Refresh();
and it :
1. do not show anything :(
2. cause that everything else disappear. (Meta data loaded earlier from MS SQL db)
So. I'd really appreciate an example for that simple case.
TIA.
Avatar
Andrey Zavyalov, PM
Hello, Łukasz.

We tested your code placed in the OnInit event using the _latest_ version. It works fine. Please update your version to the latest. If this doesn't help you, please send the source code of your Init event handler in full.
Avatar
Łukasz Wilczynski
private void QueryBuilderOnInit(object sender, EventArgs e) {
var sessionStoreItem = sender as SessionStoreItem;
var queryBuilder = sessionStoreItem.QueryBuilder;
// create an instance of the proper syntax provider for your database server.
// - use AutoSyntaxProvider if you want to detect your database server automatically
// (autodetection works in case of live database connection only);
// - use ANSI or Universal syntax provider only if you can't find the right syntax
// provider for your database server.
var syntaxProvider = new MSSQLSyntaxProvider();
queryBuilder.SyntaxProvider = syntaxProvider;
var connection = new SqlConnection(Settings.TransitDbConnectionString);
var metadataProvider = new MSSQLMetadataProvider { Connection = connection };
queryBuilder.MetadataProvider = metadataProvider;
queryBuilder.BehaviorOptions.ParsingErrorOnUnknownObjects = true;
queryBuilder.MetadataContainer.LoadAll(false);
queryBuilder.MetadataStructure.Refresh();
queryBuilder.MetadataStructure.AllowChildAutoItems = false;

MetadataStructureItem item = new MetadataStructureItem() { Caption = "Fake DB - why not a folder" };
MetadataStructureItem itemsch = new MetadataStructureItem() { Caption = "Fake schema - why not a folder" };
MetadataStructureItem itemfold = new MetadataStructureItem() { Caption = "Should be Folder" };
MetadataStructureItem iteml1 = new MetadataStructureItem() { Caption = "Definitely should be Item or folder" };
try
{
queryBuilder.MetadataStructure.BeginUpdate();
itemfold.Items.Add(iteml1);
itemsch.Items.Add(itemfold);
item.Items.Add(itemsch);
queryBuilder.MetadataStructure.Items.Add(item);
}
finally
{
queryBuilder.MetadataStructure.EndUpdate();
}
queryBuilder.MetadataStructure.Refresh();
}

And in our app it brings below effect (instead of structure it appears to be “selections” and there is no metadata from MSSQL):






We want to add folder and then to add some tables to this folder. What should we do?
And – anyway – why Transit DB (MetadataItem read by AQB from MSSQL) disappear from view (it is still in Metadatastructer object as I peek in Debug) when any modification is made?

TIA for an answer/suggestion



Avatar
Andrey Zavyalov, PM

1. Metadata structure item becomes "item", not "folder" when it gets reference to item of the Metadata Container (MetadataStructureItem.MetdataItem != null).

2. You instructed the metadata structure root node not to generate auto child items (AllowChildAutoItems = false;) thus you don't see your database structure anymore. Turning it to true will lead to loading of your database schema tree.

You can read the updated Knowledge book page for details.

Avatar
Łukasz Wilczynski
What I noticed - while debugging - setting AllowChildAutoItems to false.... clears MetadataStructure items collection - quite surprising. I still do not get why - in above example - I get list of "selectors" instead of ( what should I expect) simply folders structure? Could you share a hint?
Avatar
Andrey Zavyalov, PM
Sorry, but I don't understand your last question clearly. Database Schema Tree control in the current version of ASP.NET edition isn't actually a tree. It's a paginated list of objects with a set of selectors that represents tree structure. In your sample you have added 4 folders, one in another, that was represented as 4 selectors, one under another. The component automatically selects the content of a folder if there is only one subfolder in it.
Avatar
Łukasz Wilczynski
Hope it will clarify our requirements.
All I want is to show user structure like this:
[Folder A]
'....[Table 1]
'....[Table 2]
[Folder B]
'....[Table 3]
'....[SubFolder X]
>>'....[Table 4]

This structure need to be build dynamically at run time.
Am I able to achieve such effect?
and how? (Should we use API objects or build dynamicly XML and apply it to Metadatastructure?)
Does code sample mentioned in Knowledge book page describes such a case?
And where I can find this particular code sample (new Metadata Structure demo project)?

Thanks for any suggestions.






Avatar
Andrey Zavyalov, PM
Below is the code sample that copes with your task.
    // Create "folder A" folder
    MetadataStructureItem folder = new MetadataStructureItem();
    folder.Caption = "Folder A";
    folder.ImageIndex = queryBuilder.MetadataStructure.Structure.Options.FolderImageIndex;
    queryBuilder.MetadataStructure.Items.Add(folder);

    MetadataItem metadataItem;
    MetadataStructureItem item;

    // Add some metadata objects to "folder A" folder
    metadataItem = queryBuilder.MetadataContainer.FindItem<MetadataItem>("Table 1");
    item = new MetadataStructureItem();
    item.MetadataItem = metadataItem;
    item.MetadataName = metadataItem.Name;
    item.ImageIndex = queryBuilder.MetadataStructure.Structure.Options.UserTableImageIndex;
    folder.Items.Add(item);

    metadataItem = queryBuilder.MetadataContainer.FindItem<MetadataItem>("Table 2");
    item = new MetadataStructureItem();
    item.MetadataItem = metadataItem;
    item.MetadataName = metadataItem.Name;
    item.ImageIndex = queryBuilder.MetadataStructure.Structure.Options.UserTableImageIndex;
    folder.Items.Add(item);

    // Create "folder B" folder
    folder = new MetadataStructureItem();
    folder.Caption = "Folder B";
    folder.ImageIndex = queryBuilder.MetadataStructure.Structure.Options.FolderImageIndex;
    queryBuilder.MetadataStructure.Items.Add(folder);

    // Add some metadata objects to "folder B" folder
    metadataItem = queryBuilder.MetadataContainer.FindItem<MetadataItem>("Table 3");
    item = new MetadataStructureItem();
    item.MetadataItem = metadataItem;
    item.MetadataName = metadataItem.Name;
    item.ImageIndex = queryBuilder.MetadataStructure.Structure.Options.UserTableImageIndex;
    folder.Items.Add(item);

    // Create "subfolder" folder
    MetadataStructureItem subfolder = new MetadataStructureItem();
    subfolder.Caption = "SubFolder";
    subfolder.ImageIndex = queryBuilder.MetadataStructure.Structure.Options.FolderImageIndex;
    folder.Items.Add(subfolder);

    // Add some metadata objects to "subfolder" folder
    metadataItem = queryBuilder.MetadataContainer.FindItem<MetadataItem>("Table 4");
    item = new MetadataStructureItem();
    item.MetadataItem = metadataItem;
    item.MetadataName = metadataItem.Name;
    item.ImageIndex = queryBuilder.MetadataStructure.Structure.Options.UserTableImageIndex;
    subfolder.Items.Add(item);
Avatar
Andrey Zavyalov, PM
Before running this code please make sure that metadataItems are found, because if not, you will get the structure consisting of "folders" only.
Avatar
Łukasz Wilczynski
Well, code looks similar to my original and its effect is similar, and similarly not what we expect.
We need to show TREE structure to the user. We do not want to show dropdown selectors instead of structure.
What above sample does, is:



and what we need to show is normal tree structure/hierarchy:



Is it possible to achieve such a result in AQB?

Avatar
Andrey Zavyalov, PM
I see.

It is not possible in the current version, but we plan to implement the real tree view in October.