Оставить Присоединиться fetchXml на основе общего столбца - PullRequest
0 голосов
/ 04 декабря 2018

У меня есть две таблицы, которые не связаны, но имеют общий столбец.Я хочу объединить строки в таблице B, которые соответствуют <attribute name='substitutedproductid'> в таблице A. Таблица 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>

Таблица 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>

КакКак показано выше, обе таблицы имеют поиск (substituteproductid), который может относиться к одному и тому же продукту.В случае, если поиск одинаков, я хочу выполнить левое соединение с таблицей А. В основном, я хочу вернуть один набор сущностей из одной строки fetchXml.Как мне этого добиться?

1 Ответ

0 голосов
/ 04 декабря 2018

В основном вы должны использовать link-entity.Этот запрос должен работать для вашего сценария. Ссылается на старую дискуссию.

<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>
...