避免使用链接实体的 FetchXml 结果中的别名

Avoid Aliases in result from FetchXml with linked entities

我有以下 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"

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

有解决此问题的想法吗?

你得到了这些别名,然后它很有价值,因为你正在从链接的实体中检索数据。每当你这样做时,即从链接的实体中检索你将不得不使用别名,据我所知你无法绕过它。

我的建议是,如果您只需要来自 ListMember 实体的数据而不需要来自 List 和联系人的数据, 根据

等列表成员实体创建您的抓取
select * from listmember where listname="Test 1"

但是一旦您需要相关实体的数据,该相关实体就应该使用别名。

覆盖 select 列的 alias 的唯一选项是有效的 - 当您执行聚合函数并且我测试了下面的工作示例时。

<fetch top="50" aggregate="true" >
  <entity name="account" >
    <attribute name="businesstypecode" alias="test" groupby="true" />
    <link-entity name="contact" from="accountid" to="accountid" link-type="inner" alias="acc" >
      <attribute name="accountrolecode" alias="testing" groupby="true" />
    </link-entity>
  </entity>
</fetch>

结果:

test    testing
1       3
1   

这没有用。不知道为什么,可能是fetchxml的限制。

<fetch top="50" >
  <entity name="contact" >
    <attribute name="fullname" />
    <link-entity name="account" from="accountid" to="accountid" alias="acct" >
      <attribute name="name" alias="acctNAME" />
    </link-entity>
  </entity>
</fetch>

结果:

fullname        acct.name
arun account    arun account

即使使用查询表达式,您也会得到一个名为 AliasedValue 的特殊数据类型来处理此问题,因此这是预期的行为。 Read more