Получить XML для SQL Регистрация с фильтром - PullRequest
1 голос
/ 19 февраля 2020

Я пытаюсь построить запрос Fetch XML, эквивалентный запросу SQL, я совсем недавно использую Fetch XML:

SELECT o.opportunityid,c1.accountid
FROM dbo.opportunity o
LEFT JOIN dbo.account c1 on o.customerid = c1.accountid and o.customeridtype = 1 

в

<fetch mapping="logical" version="1.0">
  <entity name="opportunity">
  <attribute name="opportunityid" />
    <link-entity name="account" from="accountid" to="customerid" alias="A1" link-type="outer" >
        <filter type="and" >
            <condition attribute="customeridtype" operator="eq" value="1" />
        </filter>
    <attribute name="accountid" /> 
    </link-entity>

, но это выдает ошибку, говоря, что атрибут «customeridtype» не существует в сущности «account». этот атрибут взят из объекта возможности, как в запросе SQL. Как я могу это исправить?

Ответы [ 2 ]

0 голосов
/ 19 февраля 2020

Извлеките filter изнутри link-entity xml узла наружу entity узла.

Вы можете попробовать XrmToolBox fetch xml builder или Kingswaysoft sql2fetch xml онлайн-инструмент.

<fetch mapping="logical" version="1.0">
  <entity name="opportunity">
  <attribute name="opportunityid" />

    <filter type="and" >
        <condition attribute="customeridtype" operator="eq" value="1" />
    </filter>

    <link-entity name="account" from="accountid" to="customerid" alias="A1" link-type="outer" >
        <attribute name="accountid" />   
    </link-entity> 
0 голосов
/ 19 февраля 2020

Я только что запустил это в одном из моих экземпляров Dynamics и дал правильный результат

<fetch>
      <entity name="opportunity" >
        <attribute name="opportunityid" />
        <attribute name="customeridtype" />
        <filter type="and" >
          <condition attribute="customeridtype" operator="eq" value="1" />
        </filter>
        <link-entity name="account" from="accountid" to="customerid" link-type="outer" alias="Account" >
          <attribute name="accountid" alias="AccountId" />
        </link-entity>
      </entity>
    </fetch>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...