【问题标题】:FetchXML for SQL Join having filter用于具有过滤器的 SQL 连接的 FetchXML
【发布时间】:2020-06-03 14:51:57
【问题描述】:

我正在尝试构建与 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 查询中的机会实体。我该如何解决这个问题?

【问题讨论】:

  • 解决了你的问题吗?
  • 我无法在链接之外取出过滤器,因为它还有几个连接,并且该过滤器应该只应用于那个连接。但是,我已将实体单独下载到表中,并在 SQL 本身的连接中要求
  • 这就是为什么你应该把完整的代码分享给我们:)

标签: sql-server dynamics-crm fetchxml kingswaysoft


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    filter从内部link-entityxml节点取出到外部entity节点。

    你可以试试 XrmToolBox fetchxml builder 或者 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> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-12
      • 1970-01-01
      • 1970-01-01
      • 2018-08-16
      • 1970-01-01
      • 2021-12-25
      • 2013-04-13
      • 2018-02-21
      相关资源
      最近更新 更多