CRM 2011 SDK-在不检索数据行的情况下获取实体数 [英] CRM 2011 sdk - obtaining count of entities without retrieving rows of data

查看:43
本文介绍了CRM 2011 SDK-在不检索数据行的情况下获取实体数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CRM 2011 SDK与远程CRM 2011服务一起使用。我需要检索联系人总数,该总数超过20000。

I am using the CRM 2011 SDK to work with a remote CRM 2011 service. I need to retrieve the total number of contacts, which is something over 20000.

例如,我尝试了一个简单的LINQ查询。 聚合c在服务中。ContactSet放入Count()(来自这些示例,也此建议此建议),但是每个建议都花了 age ,因为下载的结果XML是整个数据记录集(即使它是仅GUID,仍然是20000 GUID及其所有XML绒毛。)

I've tried a simple LINQ query, eg. Aggregate c In service.ContactSet Into Count() (from these examples, also this suggestion and this suggestion) but each one took ages, because the resulting XML that gets downloaded is an entire recordset of data (even if it's only the GUID, that's still 20000 GUIDs and all their XML fluff).

我似乎无法找到如何简单地以返回的方式查询CRM 2011的方法。 单个数字-实体中的记录总数。可以说是标量查询。

I can't seem to find how to simply query CRM 2011 in such a way as it returns a single number - the total count of records in an entity. A "scalar query" so to speak. How is this done?

推荐答案

不幸的是,LINQ查询不支持聚合和分组。

Unfortunately, LINQ queries does not support aggregates and grouping.

文档说:


FetchXML支持QueryExpression的所有功能以及
聚合和分组。查询是作为XML语句构建的。

FetchXML Supports all the features of QueryExpression plus aggregates and grouping. Queries are built as XML statements.

因此,您唯一的选择是使用FetchXML,如下所示:

So, the only option you have is using FetchXML as follow:

string fetchQuery = @"<fetch distinct='false' mapping='logical' aggregate='true'> 
   <entity name='entity name'> 
      <attribute name='attribute name' aggregate='count' alias='aliasName'/> 
   </entity> 
</fetch>";

EntityCollection value = _serviceProxy.Execute(new FetchExpression(fetchQuery));

返回结果如下:

<resultset morerecords="0"'> 
   <result>
      <aliasName>20</aliasName>
   </result>
</resultset>

这篇关于CRM 2011 SDK-在不检索数据行的情况下获取实体数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆