2010-05-20 75 views
1

是否可以编写一个获取根实体和多个子项的FetchXML查询?我所能做的只有1:1。您可以编写单个FetchXML查询以获得1:多关系吗?

+2

您是否试过使用Stunnware的免费工具?如果可以使用FetchXML完成,那么Stunnware工具可以让你这么做,当然。 – 2010-05-20 14:54:34

+0

它不再可用。他搬家了,新网站给了你404个。希望它能被修复,但是谁知道...... – 2012-09-28 07:37:16

+0

你仍然可以通过旧链接获得它:http://www.stunnware.com/products/tools4/download。 htm – 2012-09-30 18:06:47

回答

4

不,这是不可能的。

+0

我已经低估了这一点,因为它似乎没有错。我已经添加了我自己的答案。 – 2012-09-30 18:32:05

+0

为了说明问题,此答案适用于“我可以获得单亲父母记录及其子女”这一问题。 Fetch明确提供了基本上可以进行连接的功能,您可以在每个子节点多次获取父记录的情况下,只需进行一些处理即可按照需要获取数据。 – Matt 2017-08-31 22:34:52

4

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

因此,例如,您想查找与给定帐户相关的所有联系人。这由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> 
5

James Wood is correct。取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查询得到一个根实体和多个孩子”,那么答案是很不幸的是,不行。但是,如果您能够处理重复的根数据(例如使用SSRS报告的分组功能),那么您需要的是完全可能的

0

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

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

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> 
相关问题