表查询不一致

时间:2013-01-09 14:50:45

标签: x++ dynamics-ax-2012

我有一种方法可以从表 MyConfiguration 中检索配置详细信息。目前使用的代码是:

Query query;
QueryRun queryRun;
QueryBuildDataSource qbds;
MyConfiguration config;
int rowCount;

query = new Query();
qbds = query.addDataSource(tableNum(MyConfiguration));
queryRun = new QueryRun(query);
rowCount = SysQuery::countTotal(queryRun);

该表有0或1行;如果有配置设置或使用默认值,则会有一个 if 语句,说明要使用的进程。

问题

虽然表中有一行,但查询会间歇性地返回0行。


更新

感谢David的输入,我简化了代码:

MyConfiguration config;

select firstOnly useSettings, firstField, secondField from config;

// This wasn't included in the original example, but demonstrates how it's used.
if(config){
    // These variables are defined in classDeclaration
    useCustom = config.useSettings;
    first = config.firstField;
    second = config.secondField;
}
else
{
     // No custom configuration, use defaults.
     useCustom = 0;
}

此代码位于调用主方法以查找要使用的配置时调用的方法中。

当我在开发环境中运行我的测试方法时,所有测试都通过(正在为每个测试读取配置)。但是,当从按钮的 单击 事件调用主方法时, select 不会返回任何内容(我已在调试器中检查过此内容) 。这会导致应用程序使用默认值而不是配置的值运行。如果我在调试器中手动移动执行,如果第二个 select 也没有返回任何值。

测试和表单都以相同的方式执行方法,但是从 select 语句得到的结果不同。

1 个答案:

答案 0 :(得分:1)

您的代码看起来正确。 但是,以下内容可能更容易使用和调试

MyConfiguration config;
int rowCount;
;
select firstonly config;
if(config)
{
  //Record exists
}
else
{
  //Record does not exist
}