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

有帮助吗?

解决方案

不,这是不可能的。

其他提示

詹姆斯·伍德是正确的. 。获取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>

如果您的问题确实是“可以编写一个获得一个fetchxml查询 单身的 根实体和多个孩子“那么不幸的是,答案是否定的。但是,如果您能够处理root数据的重复(例如,使用SSRS报告的分组功能),那么您需要的是完全可能

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

因此,例如,您想找到与给定帐户相关的所有联系人。这是由父顾客查找帐户的联系人在CRM中代表的。

enter image description here

<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>

我很高兴地报告有可能。我有一个对我有效的解决方案。

唯一的警告是,如果您有多个子帐户,您将为父母获得多个结果。例如:

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>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top