现在使用的方法是检查从DB读取的数组的大小.只要在其上执行其他操作,这样的背负就可以了.但是,我想知道是否有更直接的方法来查询现有的联系人数量.
我在C#中编码,但JS也是要了解,以防万一.
QueryExpression query = new QueryExpression
{
EntityName = "contact",
ColumnSet = new ColumnSet(true),
};
EntityCollection response = organizationService.RetrieveMultiple(query);
IEnumerable<Entity> entities = response.Entities;
Run Code Online (Sandbox Code Playgroud)
Dar*_*ryl 11
以下是您的选择:
以下是检索Count所需的Fetch XML和C#代码:
var xml = @"
<fetch distinct='false' mapping='logical' aggregate='true'>
<entity name='contact'>
<attribute name='contactid' alias='contact_count' aggregate='count'/>
</entity>
</fetch>";
using (var service = GetOrganizationServiceProxy())
{
var resultEntity = service.RetrieveMultiple(
new FetchExpression(xml)).Entities.First();
var count = resultEntity
.GetAttributeValue<Microsoft.Xrm.Sdk.AliasedValue>("contact_count").Value;
}
Run Code Online (Sandbox Code Playgroud)
可以聚合的实体数量限制为50,000个. 看到这个问题
如果此限制太低,您可以执行SO问题建议,并捕获异常并返回50,000.如果你需要一个精确的计数,可能最简单的方法是添加一个过滤器,将名称限制为以单个字母开头,然后执行26个不同的查询,每个字母一个.假设名称的完全均匀分布(不是这样),您应该能够获得1,300,000的最大数量.
Microsoft Site明确声明只有Fetch XML支持Grouping/Aggregate函数 - > http://msdn.microsoft.com/en-us/library/gg334607.aspx
您可以在响应上使用TotalRecordCount。
Console.WriteLine("Total number of records: " + response.TotalRecordCount);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8732 次 |
| 最近记录: |