首页 > 解决方案 > 避免 FetchXml 结果中的别名与链接实体

问题描述

我有以下 FetchXML:

<fetch>
<entity name="list" >
    <attribute name="listname" />
    <attribute name="listid" alias="List" />
    <filter type="and" >
        <condition attribute="listname" operator="eq" value="Test 1" />
    </filter>
    <link-entity name="listmember" from="listid" to="listid" intersect="true" alias="listmember" >
        <attribute name="entitytype" />
        <attribute name="listmemberid" />
        <attribute name="entityid" />
        <link-entity name="contact" from="contactid" to="entityid" alias="contact" >
            <attribute name="contactid" />
            <attribute name="owneridname" />
            <attribute name="owneridtype" />
            <attribute name="ownerid" />
        </link-entity>
    </link-entity>
</entity>

结果如下所示:

<resultset morerecords="0" paging-cookie="&lt;cookie page=&quot;1&quot;&gt;&lt;listid lastnull=&quot;1&quot; firstnull=&quot;1&quot; /&gt;&lt;/cookie&gt;">
  <result>
    <listname>Test 1</listname>
    <listmember.entitytype formattedvalue="2">2</listmember.entitytype>
    <listmember.listmemberid>{6739D9B9-xxxx-xxxx-xxxx-000D3A3852A3}</listmember.listmemberid>
    <listmember.entityid type="2">{039FD4C6-xxxx-xxxx-xxxx-000D3A385A1C}</listmember.entityid>
    <contact.contactid>{039FD4C6-xxxx-xxxx-xxxx-000D3A385A1C}</contact.contactid>
    <contact.ownerid name="CRM Test" dsc="" type="8" yomi="CRM Test">{5ABA5CBA-xxxx-xxxx-xxxx-D472F64781F6}</contact.ownerid>
</result>
</resultset>

我现在的问题是我有一种通用的方法来检索 FetchXml 返回的属性。但是由于这个已经链接了实体,所以别名被添加到结果中,例如:

<listmember.listmemberid>

所以我的检索会抛出一个错误,因为我正在寻找“listmemberid”

有没有办法避免将这些别名添加到结果中?特别是因为属性名称是唯一的?

有什么想法可以解决这个问题吗?

标签: c#dynamics-crmdynamics-crm-onlinefetchxml

解决方案


您获得了这些别名,然后它就有价值了,因为您正在从链接实体中检索数据。每当您这样做时,即从链接实体中检索,您将不得不使用别名,据我所知您无法规避它。

我可以建议的是,如果您只需要来自 ListMember 实体而不是来自 List 和联系人的数据,请根据列表成员实体创建您的提取,例如

select * from listmember where listname="Test 1"

但是,一旦您需要来自相关实体的数据,该相关实体就会被别名。


推荐阅读