Update_recordset,什么更快?

Fra*_*rme 1 x++ axapta dynamics-ax-2009

我试图避免直接通过SQL进行批量更新,并希望使用X ++作业来做,但我想要做的是相当慢.

我有大约3500多条客户记录(CustTable)要更新,这就是我所拥有的:

static void fixCustLanguageId(Args _args)
{
    CustTable custTable;
    ;

    ttsbegin;

    try {

        update_recordset custTable
        setting
            LanguageId = 'fr'
        where custTable.AccountNum like 'LML*' && custTable.LanguageId == 'fr-ca';
        ttscommit;
        info('Done updating customers');
    }
    catch
    {
        ttsabort;
        error('Error updating customers');
    }


}
Run Code Online (Sandbox Code Playgroud)

这需要很长时间才能完成,这是正常的吗?有什么办法更快地实现这个目标

谢谢

Kla*_*che 6

使用update_recordset是禁食.但是,因为custtable的update()方法被覆盖,而不是对sql进行一次调用,所以它被恢复为对每条记录的调用.此外,对所有记录执行更新方法上的代码.

如果你不想这样,你只想更新字段而不调用更新方法,你可以通过调用来解决这个问题skipDataMethods(true),如下所示:

static void fixCustLanguageId(Args _args)
{
    CustTable custTable;

    try 
    {
        ttsbegin;
        custTable.skipDataMethods(true);

        update_recordset custTable
        setting
            LanguageId = 'fr'
        where custTable.AccountNum like 'LML*' && custTable.LanguageId == 'fr-ca';
        ttscommit;
        info('Done updating customers');
    }
    catch
    {
        error('Error updating customers');
    }
}
Run Code Online (Sandbox Code Playgroud)

使用此代码将是禁食,但更新方法上的代码将不会被执行.顺便说一句,不需要在catch中调用ttsabort,您的事务将自动中止.

另一个导致update_recordset转换为每个记录更新记录的事情是在AX中为该表配置数据库日志时(请参阅:http://technet.microsoft.com/en-us/library/dd362089.aspx) .停用此日志记录,因为它对性能有很大影响.