2013-02-01 24 views
0

我使用X ++下面的代碼來獲取表名:查詢從AX取表名的時間太長

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分鐘。可能是什麼原因?任何優化?

回答

0

好的,我試了很多東西,最後我決定創建一個由所有表名組成的表。這個表將會有一個Job填充它。我正在從該表中提取記錄。

2

而不是使用ConIns,使用+ =,它會更快

tableNamesList += dict.tableName(tableId); 

ConIns有哪裏工作在容器中放置插入。 + =只是將它添加到末尾

+0

感謝您的回答,但它仍然掛起。 –

0

如前所述,避免將元素附加到容器時使用conIns(),因爲它會創建容器的新副本。使用+ =來代替追加。

另外,您可能需要檢查權限並省略臨時表格,表格地圖和其他特殊情況。標準Ax有一個方法來建立一個表格名稱查找表格,將這些事情考慮在內。有關詳細信息,請查閱Global :: pickTable()方法。

您也可以通過業務連接器避免一些調用,並以類似方式在Ax中構建整個列表,並在單個函數調用中返回。

0

如果您使用的是Dynamics Axis 2012,則可以跳過treeNode的內容並使用SysModelElement表獲取數據並立即以.Net數組的形式將其返回,以便在另一端輕鬆完成任務。

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; 
    } 
}