Left Join fetchXml 基于公共列

Left Join fetchXml based on common column

我有两个 table 不相关,但有一个共同的列。我想加入 table B 中与 Table A 中的 <attribute name='substitutedproductid'> 匹配的行。Table A 看起来像这样:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="productsubstitute">
    <attribute name='substitutedproductid' />
    <attribute name='new_quantity' />
    <attribute name='new_unit' />
    <attribute name='new_grouping' />
    <filter type="and">
      <condition attribute="productid" operator="eq" value="{guid}" />
    </filter>
  </entity>
</fetch>

Table B 看起来像这样:

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="new_contractlinedislike">
    <attribute name="new_contractlinedislikeid" />
    <attribute name="substituteproductid" />
    <attribute name="new_unit" />
    <attribute name="new_quantity />
    <attribute name="new_grouping" />
    <filter type="and">
      <condition attribute="new_contractlineid" operator="eq"  value="{guid}" />
    </filter>
  </entity>
</fetch>

如上所示,两个 table 都有一个查找 (substituteproductid),它可以指向相同的产品。在查找相同的情况下,我想对 Table A 进行左连接。基本上,我想 return 来自单个 fetchXml 字符串的单个实体集合。我怎样才能做到这一点?

基本上你必须使用link-entity。此查询应该适用于您的方案。 Referred the old discussion.

<fetch version='1.0' output-format='xml-platform' mapping='logical' >
  <entity name= 'productsubstitute' >
    <attribute name='new_quantity' />
    <attribute name='new_unit' />
    <attribute name='new_grouping' />
    <filter type='and' >
      <condition attribute='productid' operator='eq' value= '{guid}' />
    </filter>
    <link-entity name='new_contractlinedislike' from='substitutedproductid' to='substituteproductid' link-type='outer' >
      <attribute name='new_contractlinedislikeid' />
      <attribute name= 'new_grouping' />
    <filter type='and' >
      <condition attribute='new_contractlineid' operator='eq' value= '{guid}' />
    </filter>
    </link-entity>
  </entity>
</fetch>