Active Query Builder support area

Dynamic setting of altname not working on fields

Avatar
  • updated
  • Answered

We need to replace the name of the tables and the fields with names the users customise. We do this by storing Identifiers in the AltName field in the metadata. And then at load time we were hoping to substitute the identifers with the text which is stored in our database.

 

I have the following code which is run immediately after I load the metadata. 

//get the resources dictionary
var resourceDict = Helpers.Resources.GetResources();
//loop over each table and it's fields and substitute the altname with the resource name
foreach(var table in metaDataContainer.Items[0].Items[0].Items.Tables)
{
   if (! string.IsNullOrEmpty(table.AltName) && resourceDict.ContainsKey(table.AltName))
   {
      table.AltName = resourceDict[table.AltName];
   }
   //now the children - the fields
   foreach(var field in table.Items.Fields)
   {
      if (! string.IsNullOrEmpty(field.AltName) && resourceDict.ContainsKey(field.AltName))
     {
     field.AltName = resourceDict[field.AltName];
   }
}

The table names in the visual display are updated but not the fields. I have following in the debugger I can confirm that it is updating the AltName field and when I add the items to the MetadataStructure I can validate that the AltName field has the correct text. But on the canvas the incorrect name is shown.
We'd like the field names to be the names we would like. The SQL Would be the internal name but in the output on to the grid the column heading would be these field names.

I have looked at the sample for AltFieldName and that works - but not the way we do it.


Hope you can guide me on this.

Avatar
Andrey Zavyalov, PM
  • Answered

Hello, 

This is how you can update the UI and SQL text after changing alternate names.

// refresh dataSources field lists and update design pane UI
queryBuilder1.SQLQuery.RefreshDataSourcesMetadata();
// update generated SQL
queryBuilder1.SQLQuery.NotifyUpdated();