2010-05-20 26 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> 
相關問題