我正在使用 CRM 2011 SDK 来处理远程 CRM 2011 服务。我需要检索联系人总数,超过 20000。
我试过一个简单的 LINQ 查询,例如。 Aggregate c In service.ContactSet Into Count()
(来自 these examples ,还有 this suggestion 和 this suggestion )但是每个都花费了 ages,因为生成的 XML下载的是整个数据记录集(即使它只是 GUID,那仍然是 20000 个 GUID 和它们所有的 XML 绒毛)。
我似乎找不到如何简单地查询 CRM 2011,因为它返回一个数字 - 一个实体中的记录总数。可以说是“标量查询”。这是怎么做到的?
最佳答案
遗憾的是,LINQ 查询不支持聚合和分组。
文档说:
FetchXML Supports all the features of QueryExpression plus aggregates and grouping. Queries are built as XML statements.
因此,您唯一的选择是使用 FetchXML,如下所示:
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>
关于dynamics-crm-2011 - CRM 2011 sdk - 在不检索数据行的情况下获取实体计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11144390/