检索导航 属性 Dynamics WebAPI

Retrieve Navigation Property Dynamics WebAPI

我正在尝试通过父实体检索子实体的属性。总帐科目是父实体,我想要与总帐科目相关的所有总帐操作实体的详细信息。总帐操作有一个到总帐科目的查找字段。我正在使用 and 构建 url 并检索数据。

根据Microsoft Documentation

Unless you specify a smaller page size, a maximum of 5000 entities will be returned for each request. If there are more entities that match the query filter criteria, a @odata.nextLink property will be returned with the results. Use the value of the @odata.nextLink property with a new GET request to return the next page of data.

我只有 return1 个父实体和 1 个子实体,所以我不应该遇到这个障碍。然而,

当我使用 url:

https://crm.com/api/data/v8.0/ccseq_generalledgeraccounts(48513938-7d5a-e711-80e5-005056b33317)/ccseq_generalledgeraccount_ccseq_generalledgeraction_GeneralLedgerAccountID

我得到结果:

{
  "@odata.context":"https://crm.com/api/data/v8.0/$metadata#ccseq_generalledgeractions","value":[
    {
      "@odata.etag":"W/\"676070510\"","_organizationid_value":"ff05a89b-16b0-44a6-879c-26866b3a9d9d","ccseq_servicecode":"111","modifiedon":"2017-06-26T14:41:49Z","ccseq_generalledgernumber":"44000","ccseq_dollar":25.0000,"statecode":0,"ccseq_percent":0.0000000000,"statuscode":1,"_createdby_value":"3b0731e3-52bd-e611-80df-005056b33317","ccseq_jobclasscode":"111","ccseq_companycode":"111","_ccseq_generalledgeraccountid_value":"48513938-7d5a-e711-80e5-005056b33317","ccseq_dollar_base":25.0000,"_modifiedby_value":"3b0731e3-52bd-e611-80df-005056b33317","versionnumber":676070510,"exchangerate":1.0000000000,"ccseq_generalledgeractionid":"3e17f993-7d5a-e711-80e5-005056b33317","ccseq_geographycode":"111","createdon":"2017-06-26T14:41:49Z","_transactioncurrencyid_value":"863aa006-cae5-dc11-92e8-001a6449bbe7","_modifiedonbehalfby_value":null,"_createdonbehalfby_value":null,"utcconversiontimezonecode":null,"timezoneruleversionnumber":null,"importsequencenumber":null,"ccseq_name":null,"overriddencreatedon":null
    }
  ]
}

当我使用 url:

https://crm.com/api/data/v8.0/ccseq_generalledgeraccounts?$select=ccseq_code&$expand=ccseq_generalledgeraccount_ccseq_generalledgeraction_GeneralLedgerAccountID

我得到结果:

{
  "@odata.context":"https://crm.com/api/data/v8.0/$metadata#ccseq_generalledgeraccounts(ccseq_code,ccseq_generalledgeraccount_ccseq_generalledgeraction_GeneralLedgerAccountID)","value":[
    {
      "@odata.etag":"W/\"676070286\"","ccseq_code":null,"ccseq_generalledgeraccountid":"48513938-7d5a-e711-80e5-005056b33317","ccseq_generalledgeraccount_ccseq_generalledgeraction_GeneralLedgerAccountID":[

      ],"ccseq_generalledgeraccount_ccseq_generalledgeraction_GeneralLedgerAccountID@odata.nextLink":"https://crminternal.cohencpa.com/COHEN/api/data/v8.0/ccseq_generalledgeraccounts(48513938-7d5a-e711-80e5-005056b33317)/ccseq_generalledgeraccount_ccseq_generalledgeraction_GeneralLedgerAccountID"
    }
  ]
}

我的理解是这两个 url 应该 return 完全相同的数据,这将是父属性和子属性的 json 对象。这些查询有什么区别?为什么我的第二个查询 return 是实体的 odata.nextLink 而不是 json 表示?

不同之处在于,在您的第一个请求中,您是从单个记录中检索数据,而在第二个示例中,您是在检索所有总帐科目。

此时您可以想象,$expand 的工作方式会有所不同,具体取决于您检索的是单个记录还是集合(前段时间甚至不支持,您会遇到异常)以避免性能问题问题。检索集合时,WebAPI 会为您提供@odata.nextLink,您可以使用第二个 GET 来检索子记录。

您可以在 MSDN:

中看到这方面的示例

Retrieve related entities by expanding collection-valued navigation properties: If you expand on collection-valued navigation parameters to retrieve related entities for entity sets, an @odata.nextLink property will be returned for the related entities. You should use the value of the @odata.nextLink property with a new GET request to return the required data.