OData 多级查询 CDS returns 奇怪的结果在第 3 级
OData Multi-level query to CDS returns strange results at the 3rd level
我正在使用 OData WebApi 查询我们的 MS Dynamics HR Talent 安装。
我是运行这个查询:
https://nnnnnnnnnnn.crm.dynamics.com/api/data/v9.1/cdm_workers?$select=cdm_fullname,cdm_primaryemailaddress&$expand=cdm_worker_employment($select=cdm_employmentnumber,cdm_ompayrollid_custom,_cdm_companyid_value;$expand=cdm_CompanyId)
使用 OData 4.0 版。
这些实体不是自定义实体,但有些实体有一个或两个自定义字段。
返回结果时,cdm_workers 和 cdm_worker_employment 的值正是我所期望的。
但是 cdm_CompanyId 的值不是。所有字段的值都是空的,除了 cdm_companyid 这是我所期望的,还有一个额外的、意外的字段名为 '__DisplayName__
',它具有我希望在 [=40 中看到的值=].
谁能解释发生了什么,为什么我会看到这种行为?
这是我从此查询中获得的结果示例:
"value" : [ {
"@odata.etag" : "W/\"3017162\"",
"cdm_fullname" : "Mmmmmm Rrrrrr Tttttttt",
"cdm_primaryemailaddress" : "mmmm.ttttttt@xyz.org",
"cdm_workerid" : "95f1fee2-2dcb-e911-a81d-000d3a1cae2a",
"cdm_worker_employment" : [ {
"@odata.etag" : "W/\"3767381\"",
"cdm_employmentnumber" : "EMPL0001029",
"cdm_ompayrollid_custom" : "444",
"_cdm_companyid_value" : "38d41deb-6888-e911-a81a-000d3a1cae2a",
"_cdm_workerid_value" : "95f1fee2-2dcb-e911-a81d-000d3a1cae2a",
"cdm_employmentid" : "bcb1f5df-2dcb-e911-a821-000d3a1ca610",
"cdm_CompanyId" : {
"_createdby_value" : null,
"overriddencreatedon" : null,
"_ownerid_value" : null,
"timezoneruleversionnumber" : null,
"_modifiedonbehalfby_value" : null,
"utcconversiontimezonecode" : null,
"_modifiedby_value" : null,
"createdon" : null,
"_owningbusinessunit_value" : null,
"_owningteam_value" : null,
"statuscode" : null,
"cdm_name" : null,
"versionnumber" : null,
"_createdonbehalfby_value" : null,
"cdm_companyid" : "38d41deb-6888-e911-a81a-000d3a1cae2a",
"_owninguser_value" : null,
"statecode" : null,
"cdm_companycode" : null,
"modifiedon" : null,
"importsequencenumber" : null,
"__DisplayName__" : "100",
"IsReferencedQueryCall" : true
}
} ]
相比之下,这是我针对此查询获得的结果:https://nnnnnnnnnnn.crm.dynamics.com/api/data/v9.1/cdm_companies?$filter=cdm_companyid+eq+'38d41deb-6888-e911-a81a-000d3a1cae2a'
"value" : [ {
"@odata.etag" : "W/\"3497456\"",
"_owningbusinessunit_value" : "f1ed9fcc-496e-e911-a9b7-000d3a152d6d",
"cdm_companyid" : "38d41deb-6888-e911-a81a-000d3a1cae2a",
"cdm_name" : "International",
"statecode" : 0,
"statuscode" : 1,
"_createdby_value" : "fe5e4d27-0b70-e911-a817-000d3a1ca508",
"cdm_companycode" : "100",
"_ownerid_value" : "fe5e4d27-0b70-e911-a817-000d3a1ca508",
"_modifiedby_value" : "fe5e4d27-0b70-e911-a817-000d3a1ca508",
"_owninguser_value" : "fe5e4d27-0b70-e911-a817-000d3a1ca508",
"createdon" : "2019-06-06T14:39:47Z",
"versionnumber" : 3497456,
"modifiedon" : "2019-10-24T07:59:37Z",
"overriddencreatedon" : null,
"timezoneruleversionnumber" : null,
"_modifiedonbehalfby_value" : null,
"utcconversiontimezonecode" : null,
"_owningteam_value" : null,
"_createdonbehalfby_value" : null,
"importsequencenumber" : null
} ]
我期待在先前结果的 cdm_CompanyId 对象中看到此数据。
我们从支持请求中得到的答复是 multi-level 扩展不受支持。
微软文档里有个'documentation mismatch'.
此页面:https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/retrieve-entity-using-web-api#options-to-apply-to-expanded-entities 说:
“您可以在为 collection-valued 导航 属性 返回的实体上应用某些系统查询选项。在 collection-valued 导航 属性。你可以使用 $select、$filter、$orderby、$top 和 $expand。",这意味着你可以扩展一个扩展,即转到第三级(并进一步?).
但是此页面:https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/data-entities/odata#odata-services 涉及将 OData 与 Dynamics 365 结合用于财务和运营,它说:
“可用的查询选项是:. . . $expand(仅支持 first-level 扩展)”。
所以简短的回答是,使用OData查询Talent时不支持扩展到第三层。
我正在使用 OData WebApi 查询我们的 MS Dynamics HR Talent 安装。
我是运行这个查询:
https://nnnnnnnnnnn.crm.dynamics.com/api/data/v9.1/cdm_workers?$select=cdm_fullname,cdm_primaryemailaddress&$expand=cdm_worker_employment($select=cdm_employmentnumber,cdm_ompayrollid_custom,_cdm_companyid_value;$expand=cdm_CompanyId)
使用 OData 4.0 版。
这些实体不是自定义实体,但有些实体有一个或两个自定义字段。
返回结果时,cdm_workers 和 cdm_worker_employment 的值正是我所期望的。
但是 cdm_CompanyId 的值不是。所有字段的值都是空的,除了 cdm_companyid 这是我所期望的,还有一个额外的、意外的字段名为 '__DisplayName__
',它具有我希望在 [=40 中看到的值=].
谁能解释发生了什么,为什么我会看到这种行为?
这是我从此查询中获得的结果示例:
"value" : [ {
"@odata.etag" : "W/\"3017162\"",
"cdm_fullname" : "Mmmmmm Rrrrrr Tttttttt",
"cdm_primaryemailaddress" : "mmmm.ttttttt@xyz.org",
"cdm_workerid" : "95f1fee2-2dcb-e911-a81d-000d3a1cae2a",
"cdm_worker_employment" : [ {
"@odata.etag" : "W/\"3767381\"",
"cdm_employmentnumber" : "EMPL0001029",
"cdm_ompayrollid_custom" : "444",
"_cdm_companyid_value" : "38d41deb-6888-e911-a81a-000d3a1cae2a",
"_cdm_workerid_value" : "95f1fee2-2dcb-e911-a81d-000d3a1cae2a",
"cdm_employmentid" : "bcb1f5df-2dcb-e911-a821-000d3a1ca610",
"cdm_CompanyId" : {
"_createdby_value" : null,
"overriddencreatedon" : null,
"_ownerid_value" : null,
"timezoneruleversionnumber" : null,
"_modifiedonbehalfby_value" : null,
"utcconversiontimezonecode" : null,
"_modifiedby_value" : null,
"createdon" : null,
"_owningbusinessunit_value" : null,
"_owningteam_value" : null,
"statuscode" : null,
"cdm_name" : null,
"versionnumber" : null,
"_createdonbehalfby_value" : null,
"cdm_companyid" : "38d41deb-6888-e911-a81a-000d3a1cae2a",
"_owninguser_value" : null,
"statecode" : null,
"cdm_companycode" : null,
"modifiedon" : null,
"importsequencenumber" : null,
"__DisplayName__" : "100",
"IsReferencedQueryCall" : true
}
} ]
相比之下,这是我针对此查询获得的结果:https://nnnnnnnnnnn.crm.dynamics.com/api/data/v9.1/cdm_companies?$filter=cdm_companyid+eq+'38d41deb-6888-e911-a81a-000d3a1cae2a'
"value" : [ {
"@odata.etag" : "W/\"3497456\"",
"_owningbusinessunit_value" : "f1ed9fcc-496e-e911-a9b7-000d3a152d6d",
"cdm_companyid" : "38d41deb-6888-e911-a81a-000d3a1cae2a",
"cdm_name" : "International",
"statecode" : 0,
"statuscode" : 1,
"_createdby_value" : "fe5e4d27-0b70-e911-a817-000d3a1ca508",
"cdm_companycode" : "100",
"_ownerid_value" : "fe5e4d27-0b70-e911-a817-000d3a1ca508",
"_modifiedby_value" : "fe5e4d27-0b70-e911-a817-000d3a1ca508",
"_owninguser_value" : "fe5e4d27-0b70-e911-a817-000d3a1ca508",
"createdon" : "2019-06-06T14:39:47Z",
"versionnumber" : 3497456,
"modifiedon" : "2019-10-24T07:59:37Z",
"overriddencreatedon" : null,
"timezoneruleversionnumber" : null,
"_modifiedonbehalfby_value" : null,
"utcconversiontimezonecode" : null,
"_owningteam_value" : null,
"_createdonbehalfby_value" : null,
"importsequencenumber" : null
} ]
我期待在先前结果的 cdm_CompanyId 对象中看到此数据。
我们从支持请求中得到的答复是 multi-level 扩展不受支持。
微软文档里有个'documentation mismatch'.
此页面:https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/retrieve-entity-using-web-api#options-to-apply-to-expanded-entities 说:
“您可以在为 collection-valued 导航 属性 返回的实体上应用某些系统查询选项。在 collection-valued 导航 属性。你可以使用 $select、$filter、$orderby、$top 和 $expand。",这意味着你可以扩展一个扩展,即转到第三级(并进一步?).
但是此页面:https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/data-entities/odata#odata-services 涉及将 OData 与 Dynamics 365 结合用于财务和运营,它说: “可用的查询选项是:. . . $expand(仅支持 first-level 扩展)”。
所以简短的回答是,使用OData查询Talent时不支持扩展到第三层。