首页 > 解决方案 > 用于具有过滤器的 SQL 连接的 FetchXML

问题描述

我正在尝试构建与 SQL 查询等效的 FetchXML,但我对使用 FetchXML 还是很陌生:

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”。该属性来自 SQL 查询中的机会实体。我怎样才能解决这个问题?

标签: sql-serverdynamics-crmfetchxmlkingswaysoft

解决方案


我刚刚在我的一个 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>

推荐阅读