最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

RecordInserList类用于优化插入操作 / RecordInserList class for optimized insert operation

网络文摘 William 87浏览 0评论
Hi Folks,
RecordInsertList class is really useful and fastest way to insert records in AX table(s). This method is useful you don't want to run any validation while insertion for an example; insert in a temp table or SSRS reports. 
Below is the simplest example of set based RecordInserList class,
void copyVendor()
{
    VendTable    sourceVend;
    MyTmpTable   targetVend;
    //RecordInserList calss decarion
    RecordInsertList VendList;
  //Object initialization
    VendList = new RecordInsertList(tableNum(Vendtable));
    while select sourceVend
    where sourceVend.vendgroupId == ‘Local’
    {
        targetVend.data(sourceVend);
        targetVend.vendorAccount = sourceVend.vendorAccount;
           .
           .
           .
           .
        VendList.add(targetVend);
    }
    VendList.insertDatabase(); //mandatory call
}
Another example from MSDN
public void tutorialRecordInsertList()
    {
        MyTable myTable;
        RecordInsertList insertList = new RecordInsertList(
            myTable.TableId,
            True);
        int i;
        for ( i = 1; i <=  100; i++ )
        {
            myTable.value = i;
            insertList.add(myTable);
        }
        insertList.insertDatabase();
    }
RecordInserList class will capture all record in temp and hit the DataBase only once when we call insertDatabase(). add() insert certain blocks followed by insertDatabase to complete the insert operation. 
This is how we can reduce the SQL call and optimize the performance as well.
Cheers,
Harry
Follow us on Facebook to keep in rhythm with us. @Facebook
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址