【问题标题】:FetchXml: get only records for which all related records satisfy the conditionFetchXml:只获取所有相关记录都满足条件的记录
【发布时间】:2020-09-03 06:52:07
【问题描述】:

Dynamics 365 v8.2。 FetchXml。

每个isv_entity1 记录可以与一个或多个isv_entity2 记录链接(一对多)。我需要 only isv_entity1 记录 all 链接的 isv_entity2 记录对应某些条件。如果至少有一条链接的isv_entity2 记录不满足条件,则isv_entity1 记录不应落入选择范围内。

我怎样才能通过 FetchXml 做到这一点?

如果我要使用这个查询:

<fetch distinct='true' >
  <entity name='isv_entity1' >
    <attribute name='isv_entity1id' />    
    <link-entity name='isv_entity2' from='isv_entity2id' to='isv_entity2id' >
      <filter type='and' >
          <condition attribute='isv_someProp' operator='eq' value='someValue' />
      </filter>
    </link-entity>
  </entity>
</fetch>

然后我得到isv_entity1 记录有至少一个 链接isv_entity2 对应条件。但这和我需要的不一样。

【问题讨论】:

    标签: dynamics-crm microsoft-dynamics fetchxml


    【解决方案1】:

    你需要的是:find all parent records where all child records have a given value (but not just some child records)

    以上是您要求的 sql 等价物,不幸的是,FetchXML 不支持子查询。

    因此,您要么必须使用两个查询,要么查询所有记录并迭代以验证/过滤符合您条件的结果

    【讨论】:

      猜你喜欢
      • 2017-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多