0

我在 X++ 中使用以下代码来获取表名:

client server public static container tableNames()
{
tableId         tableId;
int             tablecounter;
Dictionary      dict = new Dictionary();
container       tableNamesList;

for (tablecounter=1; tablecounter<=dict.tableCnt(); tablecounter++)
{
    tableId = dict.tableCnt2Id(tablecounter);
    tableNamesList = conIns(tableNamesList,1,dict.tableName(tableId));
}

return tableNamesList;
}

业务连接器代码:

tablesList = (AxaptaContainer)Global.ax.
                CallStaticClassMethod("Code_Generator", "tableNames");

for (int i = 1; i <= tablesList.Count; i++)
{
    tableName = tablesList.get_Item(i).ToString();
    tables.Add(tableName);
}

应用程序在获取数据时挂起 2 到 3 分钟。可能是什么原因?有什么优化吗?

4

4 回答 4

2

而不是使用ConIns,使用+=,会更快

tableNamesList += dict.tableName(tableId);

ConIns 必须确定在容器中放置插件的位置。+= 只是将其添加到末尾

于 2013-02-01T13:27:00.187 回答
0

如前所述,在将元素附加到容器时避免使用 conIns(),因为它会生成容器的新副本。使用 += 代替追加。

此外,您可能希望检查权限并忽略临时表、表映射和其他特殊情况。标准 Ax 有一种方法来构建表名查找表单,该表单将这些事情考虑在内。检查方法 Global::pickTable() 了解详细信息。

You could avoid some calls through the business connector as well and build the entire list in Ax in a similar way and return that in a single function call.

于 2013-02-01T14:55:06.697 回答
0

If you are using Dynamics Ax 2012, you could skip the treeNode stuff and use the SysModelElement table to fetch the data and return it immediately as a .Net Array to easy up things on the other side.

public static System.Collections.ArrayList FetchTableNames_ModelElementTables()
{
    SysModelElement                 element;
    SysModelElementType             elementType;
    System.Collections.ArrayList    tableNames = new System.Collections.ArrayList();
    ;  

    // The SysModelElementType table contains the element types 
    // and we need the recId for the next selection
    select firstonly RecId
    from  elementType
    where elementType.Name == 'Table';

    // With the recId of the table element type, 
    // select all of the elements with that type (hence, select all of the tables)
    while select Name
        from element
        where element.ElementType == elementType.RecId
    {
        tableNames.Add(element.Name);
    }

    return tableNames;
    }
}
于 2013-02-03T21:24:27.330 回答
0

Alright, I have tried a lot of things and in the end, I decided to create a table consisting of all table names. This table will have a Job populating it. I am fetching records from this table.

于 2013-02-05T10:24:18.997 回答