Love those days when people send their gems and discoveries to jar@crmtipoftheday.com – other people’s cleverness tend to rub off on us, making us a bit smarter every single post.
Aron Fischman from xRM Edge LLC made this intricate discovery while working on a product that calculates aggregates on CRM data. In his travels he’s noticed that with ExecuteFetchRequest we can run aggregates on most entities, but with RetrieveMultiple, certain entities are excluded.
For example, the postrole entity does not support RetrieveMultiple, but we can still run aggregates against it using ExecuteFetchRequest. The behavior is the same using CrmServiceClient.
Here is some sample code:
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Client;
using Microsoft.Xrm.Client.Services;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Tooling.Connector;
namespace Lab_ExecuteFetchVsRetrieveMultiple
{
class Program
{
static void Main(string[] args)
{
var fetch = @"<fetch aggregate='true' mapping='logical'>
<entity name='postrole'>
<attribute name='postroleid' alias='aggregate_result' aggregate='count' />
</entity>
</fetch>";
var connectionString = "Url=https://foobar.crm.dynamics.com; Username=user@foobar.onmicrosoft.com; Password=myPass; AuthType=Office365";
var connection = CrmConnection.Parse(connectionString);
var executeFetchReq = new ExecuteFetchRequest { FetchXml = fetch };
//Try with IOrganizationService
var orgService = new OrganizationService(connection);
//Works
var orgSvcExecuteFetchResponse = (ExecuteFetchResponse)orgService.Execute(executeFetchReq);
//Doesn't work
var orgSvcRetrieveMultipleResponse = orgService.RetrieveMultiple(new FetchExpression(fetch));
//Try with CrmServiceClient:
var crmSvcClient = new CrmServiceClient(connectionString);
//Works
var crmSvcExecuteFetchResponse = crmSvcClient.Execute(executeFetchReq);
//Doesn't work
var crmSvcRetrieveMultipleResponse = crmSvcClient.RetrieveMultiple(new FetchExpression(fetch));
}
}
}
The ExecuteFetchRequest works fine, but the RetrieveMultiple throws an exception:

When pressed, Aron dug out the whole list of entities with the same behavior.
- AuthorizationServer
- BusinessDataLocalizedLabel
- BusinessProcessFlowInstance
- Calendar
- CalendarRule
- ChildIncidentCount
- ComplexControl
- DependencyFeature
- ImageDescriptor
- LookUpMapping
- MailboxStatistics
- MetadataDifference
- MultiEntitySearch
- MultiEntitySearchEntities
- OrganizationUI
- PartnerApplication
- PostRegarding
- PrincipalAttributeAccessMap
- PrincipalEntityMap
- PrincipalObjectAccessReadSnapshot
- PrincipalSyncAttributeMap
- QueueItemCount
- QueueMemberCount
- RecordCountSnapshot
- RollupJob
- RollupProperties
- SharePointDocument
- SqlEncryptionAudit
- Subscription
- SubscriptionClients
- SubscriptionManuallyTrackedObject
- SubscriptionSyncInfo
- SyncAttributeMapping
- SyncAttributeMappingProfile
- SystemApplicationMetadata
- SystemForm
- SystemUserManagerMap
- SystemUserSyncMappingProfiles
- TeamSyncAttributeMappingProfiles
- TimeZoneLocalizedName
- TraceAssociation
- TraceRegarding
- UserApplicationMetadata
- WorkflowWaitSubscription
of the