问题描述
Table table;
select *
from table
where this.id != table.id
&& this.foo(table);
我正在尝试从X ++代码中的表中进行选择.将该表与该表中的记录(this
)进行比较.
I am trying to make a selection from a table in X++ code.The table is compared against a record from the table (this
).
如果一条记录的ID与表中的另一条记录的ID不相等并且foo()
中的其他几个条件评估为true,则应将一条记录添加到选择中.计划是使this.foo(table)
与表中的其他记录一起评估记录.
A record shall be added to the selection if the id of the record and another record from the table do not equal and several other conditions in foo()
evaluate to true.The plan is to make this.foo(table)
evaluate the record together with each other record in the table.
当我将foo()
中的代码直接插入到调用中时,它可以正常工作.但是,在调用该方法时,它看起来像table
没有任何引用.
When I insert the code from foo()
directly into the call, it works just fine. However, when calling the method, it appears like table
does not hold any reference.
我对选择语句的工作方式不了解什么?方法只被评估一次吗?
What am I not understanding about the way, select statements work?Are methods just evaluated once?
推荐答案
您不能在AX的select
语句的where
表达式中使用方法(在此情况下,也不能用于其他任何部分).您的示例将无法成功编译.
You cannot use methods in the where
expression (nor in any other part, for that matter) of the select
statement in AX. Your example will not compile successfully.
您可以尝试将foo
方法的逻辑合并到where
表达式中,或者遍历select
语句的结果并为每个记录分别调用方法foo
,例如:
You can either try incorporating the logic of your foo
method in the where
expression or iterate through the result of the select
statement and call method foo
for each record individually e.g.:
Table table;
while select table
where table.id != this.id
{
if (this.foo(table))
{
info(table.id);
}
}
这篇关于在where语句中使用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!