【问题标题】:Can you write a single FetchXML query to get 1:many relationship?您可以编写一个 FetchXML 查询来获得 1:many 关系吗?
【发布时间】:2011-02-21 22:09:54
【问题描述】:

是否可以编写一个获取根实体和多个子实体的单个 FetchXML 查询?我所能做的就是1:1。

【问题讨论】:

  • 您是否尝试过使用 Stunnware 的免费工具?如果可以使用 FetchXML 完成,那么 Stunnware 工具肯定会让您这样做。
  • 它不再可用。他搬家了,新网站给了你 404。希望它会得到修复,但谁知道......
  • 您仍然可以通过旧链接获取它:stunnware.com/products/tools4/download.htm

标签: dynamics-crm fetchxml


【解决方案1】:

除非我误解了这个问题,否则这是很有可能的。

例如,您想查找与给定帐户相关的所有联系人。这在 Crm 中由客户联系人上的父客户查找来表示。

<fetch mapping="logical" count="100" version="1.0">
    <entity name="account">
        <attribute name="name" />
        <link-entity name="contact" from="parentcustomerid" to="accountid">
            <attribute name="fullname" />
        </link-entity>
    </entity>
</fetch>

这会为您提供如下所示的结果集:

<resultset morerecords="0" paging-cookie="&lt;cookie page=&quot;1&quot;&gt;&lt;accountid last=&quot;{E704FAD6-2D4B-E111-9FED-00155D828444}&quot; first=&quot;{AD912122-6B3C-E111-9B37-00155D828444}&quot; /&gt;&lt;/cookie&gt;">
    <result>
        <name>RGD Mining Inc</name>
        <accountid>{E704FAD6-2D4B-E111-9FED-00155D828444}</accountid>
        <accountid.fullname>Bill Miner</accountid.fullname>
    </result>
    <result>
        <name>RGD Mining Inc</name>
        <accountid>{E704FAD6-2D4B-E111-9FED-00155D828444}</accountid>
        <accountid.fullname>Green</accountid.fullname>
    </result>
</resultset>

【讨论】:

    【解决方案2】:

    James Wood is correct。 Fetch XML 是递​​归的,因此通过使用链接实体,您可以获得所需的信息。

    例如,以下是有效的:

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
      <entity name="account">
        <attribute name="name" />
        <attribute name="primarycontactid" />
        <attribute name="telephone1" />
        <attribute name="accountid" />
        <order attribute="name" descending="false" />
        <link-entity name="contact" from="parentcustomerid" to="accountid" alias="aj">
            <attribute name="firstname" />
            <attribute name="lastname" />
            <attribute name="telephone1" />
            <link-entity name="businessunit" from="businessunitid" to="owningbusinessunit" alias="ak">
                <attribute name="name" />
                <attribute name="address1_line1" />
                <attribute name="address1_line2" />
                <attribute name="address1_line3" />
                <filter type="and">
                  <condition attribute="name" operator="not-null" />
                </filter>
            </link-entity>
        </link-entity>
      </entity>
    </fetch>
    

    如果您的问题确实是“是否可以编写一个获取 SINGLE 根实体和多个子实体的单个 FetchXML 查询”,那么很遗憾,答案是否定的。但是,如果您能够处理重复的根数据(例如使用 SSRS 报告的分组功能),那么您所需要的完全有可能

    【讨论】:

      【解决方案3】:

      不,这是不可能的。

      【讨论】:

      • 我对此投了反对票,因为它似乎不正确。我已经添加了自己的答案。
      • 为澄清起见,此答案针对“我可以获得单亲记录及其子记录”这一问题。 Fetch 确实提供了本质上进行连接的能力,您可以在其中多次获取父记录以及每个子记录,您只需进行一些处理即可以您想要的方式获取数据。
      【解决方案4】:

      我很高兴地报告这是可能的。我有一个适合我的解决方案。

      唯一需要注意的是,如果您有多个子帐户,您将为父帐户获得多个结果。例如:

      parent 1: child 1
      parent 2: child 1
      parent 2: child 2
      

      这意味着您必须通过排序函数运行结果,以获取多维数组中父项下的所有子项,或获取平面数组中的所有帐户作为唯一条目。

      此外,这只会下降一个级别。如果您的层次结构是多级的,则需要修改此代码。

      <fetch distinct="false" mapping="logical"> 
         <entity name="account">     
              <attribute name="name" />
              <link-entity name="account"  alias="childaccount" to="accountid" from="parentaccountid"  link-type="outer">
                  <attribute name="name" alias="childname" />
              </link-entity>
          </entity>           
      </fetch>
      

      【讨论】:

        猜你喜欢
        • 2021-12-09
        • 1970-01-01
        • 1970-01-01
        • 2018-11-16
        • 1970-01-01
        • 2012-03-16
        • 2021-01-01
        • 2021-09-06
        • 1970-01-01
        相关资源
        最近更新 更多