How To : Obtain Records Count Without Retrieving Rows of Data in CRM Using C# SDK


Let's suppose we have a scenario that requires to get only records count of the entity "Account".


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

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

              Returned result will be something as follow:

<resultset morerecords="0"'>

Note: you can check how to create  Service Proxy at the following link