我正在尝试构建与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>
但这引发错误,表明实体“ account”中不存在属性“ customeridtype”。该属性来自机会实体,如在SQL查询中一样。我该如何解决?
我刚刚在我的一个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>
从filter
xml节点的内部将link-entity
取出到entity
节点的外部。
您可以尝试使用XrmToolBox fetchxml构建器或Kingswaysoft sql2fetchxml联机工具。
<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>