Rest 在展开查询中选择之前进行OData筛选

Rest 在展开查询中选择之前进行OData筛选,rest,dynamics-crm,odata,query-string,odata-v4,Rest,Dynamics Crm,Odata,Query String,Odata V4,我正在为Dynamics 365中的元数据编写一个查询,但我认为这个问题对于任何OData查询都是普遍存在的 我的问题如下: 在动力学中,实体中可以有多种类型的字段,例如字符串、布尔或查找。我想编写一个查询,返回查找所寻址的实体类型 {url}/api/data/v9.0/EntityDefinitions(LogicalName='Account') ?$select= LogicalName &$expand= Attributes( $select=

我正在为Dynamics 365中的元数据编写一个查询,但我认为这个问题对于任何OData查询都是普遍存在的

我的问题如下:

在动力学中,实体中可以有多种类型的字段,例如字符串、布尔或查找。我想编写一个查询,返回查找所寻址的实体类型

{url}/api/data/v9.0/EntityDefinitions(LogicalName='Account')
?$select=
    LogicalName
&$expand=
    Attributes(
        $select=
            LogicalName,
            AttributeType,
            Targets; -- Problematic property
        $filter=
      AttributeType+eq+Microsoft.Dynamics.CRM.AttributeTypeCode'Lookup')
如果我没有在这个查询中包括select for TARGET,我会得到正确的结果,即YR AttributeType为Lookup的所有属性

但当我要求目标也包括在内时,我会收到一条错误消息

Could not find a property named 'Targets' on type 'Microsoft.Dynamics.CRM.AttributeMetadata
因为目标属性只存在于那些属于查找类型的属性上,因此从字符串属性中选择此列将失败并引发此错误

在选择列之前,是否有一种方法可以先筛选查找?我发现评估的顺序是

$filter、$inlinecount、$orderby、$skiptoken、$skip、$top、$expand、$select、$format


这正是我所需要的,只是我认为在$expand属性中调用时,这个顺序不一样。

要获取查找实体,您可能会更幸运地对许多OneRelationships而不是属性进行$expand,并获取ReferencedEntity值

像这样的方法应该会奏效: …/api/data/v9.1/EntityDefinitionsLogicalName='account' ?$select=逻辑名称 &$expand=manytonerelationships$select=referencedAttribute,ReferencedEntity

结果子集:

{@odata.context:$metadataEntityDefinitionsLogicalName,manytonerelationships引用属性,ReferencedEntity/$entity,LogicalName:account,MetadataId:70816501-edb9-4740-a16c-6a5efbc05d84,manytonerelationships:[{referencedAttribute:msdyn_accountkpiid,ReferencedEntity:msdyn_accountkpiitem,MetadataId:2a712c96-09b1-e811-a842-000D33BDBD},{参考属性:首选设备ID,参考实体:设备,元数据ID:b4b462b5-ee78-467d-a97a-45264d234816},{参考属性:主要联系人ID,参考实体:联系人,元数据ID:410707b1-9554-4cd9-8437-6608b1802904},{参考属性:主ID,参考实体:帐户,元数据ID:51fa4af7-93d0-4f06-8949-38a0036ddc64},{ReferenceAttribute:preferredsystemuserid,ReferencedEntity:systemuser,MetadataId:a6b48e23-fada-4b7f-8655-530bba050765},{ReferenceAttribute:createdbyexternalparty,ReferencedEntity:externalparty,MetadataId:9967fe7d-84ee-4a26-9ad7-a8fdbdfa2316},{referencedAttribute:modifiedby,ReferencedEntity:systemuser,MetadataId:8be02a9d-0776-4c76-b35f-1c92dd791d9e},{referencedAttribute:parentaccountid,ReferencedEntity:account,MetadataId:57511732-b553-4cfb-bcf2-d280f9f8c6f1},{referencedAttribute:entityimageid,ReferencedEntity:imagedescriptor,MetadataId:5b4942d5-1fcd-49ca-91c0-2737F104F3}

另外,作为参考,我尝试在属性和目标上进行$expand: ../api/data/v9.1/EntityDefinitionsLogicalName='account'?$select=LogicalName&$expand=Attributes$filter=AttributeType+eq+Microsoft.Dynamics.CRM.AttributeType代码%27查找%27&$expand=Targets

它抛出一个错误:

多次指定了查询选项“$expand”,但必须是 最多指定一次


如果用逗号分隔属性和多个OneRelationships,则可以在同一调用中展开它们

GET https://{{baseUrl}}/api/data/v9.1/EntityDefinitions(LogicalName='account')?$select=LogicalName,EntitySetName&$expand=Attributes($select=LogicalName),ManyToOneRelationships($select=ReferencingAttribute,ReferencedEntity)

您好,谢谢您的回复。元数据的扩展非常有帮助。我曾尝试专门调用元数据端点,但我没有想到您可以扩展关系而不是属性。此查询成功了。也可供参考:我正在编写一些内容,以获取程序需要映射的所有数据,即downl从查找中加载值。我必须实现逻辑来将其拆分为多个调用,特别是因为Dynamics一次仅限于一个展开调用