1

I have an ODATA query that pulls the first record from the Dynamics AX table and ignores the $filter clause when the $top parameter is the first parameter. However, it pulls the correct record for the $filter clause when the $top parameter is at the end of the query.

Question: How do I make the OData server honor the full query no matter where the $top parameter is placed?

the following two cases return identical results:

Case 1: https://url/data/Users?$top=1

{
     "@odata.context":"https://url/data/$metadata#Users","value":[
     {
        "@odata.etag":"W/\"J5zEx4NDg33OD2YyM4TEs5NTY6zNz7E0ND7U3Nic=\"",
        "Id":"first_user_in_the_table",
        "Alias":"first_user_in_the_table@domain.com",
        "Name":"first_user_in_the_table"
     }
   ]
 }

Case 2: https://url/data/Users?$top=1&$filter=Alias%20eq%20%27specific_user@domain.com%27

{
    "@odata.context":"https://url/data/$metadata#Users","value":[
    {
        "@odata.etag":"W/\"J5zEx4NDg33OD2YyM4TEs5NTY6zNz7E0ND7U3Nic=\"",
        "Id":"first_user_in_the_table",
        "Alias":"first_user_in_the_table@domain.com",
        "Name":"first_user_in_the_table"
    }
  ]
}

However, when I move the $top parameter to the end of the query string I get the correct result.

Case 3: https://url/data/Users?$filter=Alias%20eq%20%27specific_user@domain.com%27&$top=1

{
    "@odata.context":"https://url/data/$metadata#Users","value":[
    {
        "@odata.etag":"W/\"Jz3kz4Nj5g2N6zcz7MCw81Nj9M3M2TU3w4NT4c54Jw==\"",
        "Id":"specific_user",
        "Alias":"specific_user@domain.com",
        "Name":"The Specific User I Actually Want"
    }
  ]
}
4

1 回答 1

1

据我了解OData 规范,这是不正确的行为。我基于11.2 Requesting Data声明$top查询选项应该在查询选项的最后和之后进行评估$filter。此外,第 2 节。OData ABNF 构造规则的查询选项似乎表明查询选项可以以任何顺序出现在 URL 中。

这表明此特定行为可能已被错误地实现。如果不实施自定义服务,包装现有服务以根据需要重新排序查询选项,您可能无法解决这个问题。我还假设这会影响所有 Odata 服务的行为。

我建议您向 Microsoft 创建一个支持请求,以便他们解决这个问题。

于 2020-03-04T21:43:40.257 回答