簡體   English   中英

從FetchXML訪問第二級鏈接的實體

[英]Access second level linked entity from FetchXML

這是fetchXML:

<fetch version='1.0' mapping='logical' distinct='true'>
  <entity name='listmember'>
    <link-entity name='contact' from='contactid' to='entityid' alias='c'>
      <attribute name='contactid' />
      <attribute name='telephone1' />

      <link-entity name='phonecall' from='ic_customer' to='contactid' alias='pc' link-type='outer'>
        <attribute name='activityid' />
        <attribute name='ic_end' />
        <filter type='and'>
          <filter type='or'>
            <condition attribute='statuscode' operator='eq' value='1' />
          </filter>
        </filter>
      </link-entity>

      <filter type='and'>
        <condition attribute='statecode' operator='eq' value='0' />
        <condition attribute='telephone1' operator='not-null' />
        <condition attribute='donotphone' operator='eq' value='0' />
      </filter>
    </link-entity>
    <filter type='and'>
      <condition attribute='listid' operator='in'><value>{ed0fa81c-1b65-e611-80ee-5065f38be311}</value></condition>
      <condition entityname='pc' attribute='activityid' operator='null' />
    </filter>
  </entity>
</fetch>

現在,當我通過C#中的RetrieveMultiple方法獲取對象時,我想訪問ic_end屬性。

我試圖通過以下方式獲取屬性:

var endDate = (DateTime)((AliasedValue)contact["c.pc.ic_end"]).Value;

我收到一個錯誤,找不到該名稱的屬性。

有什么建議么?

這里的幾件事:

首先也是最重要的是,檢索鏈接實體屬性的方式不正確,這些屬性以alias.attributename (在這種情況下為pc.ic_end)的格式返回。

還要始終根據您的加入條件檢查屬性是否存在,但可能不會總是返回該屬性。 檢索屬性邏輯應遵循以下原則:

if (contact.Attributes.Contains("pc.ic_end") && 
    contact.Attributes["pc.ic_end"] != null)
{
    var endDate = (DateTime) ((AliasedValue) contact["pc.ic_end"]).Value;
}

鏈接實體名稱=“電話”,從=“ ic_customer”到=“ contactid”,別名=“ pc”,鏈接類型=“外部”

我收到一個錯誤,找不到該名稱的屬性。

一旦將鏈接類型指定為外部,所有具有或沒有電話記錄的聯系人都將被返回。 因此,這是預期的行為,您需要檢查該屬性在返回的屬性列表中是否存在。

如果您希望查詢僅返回帶有電話的聯系記錄,請使用自然內部聯接

<link-entity name='phonecall' from='ic_customer' to='contactid' alias='pc'>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM