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

Export Translations in Dynamics CRM Progrmatillcally

SDKThe following code illustrates how to export Translation file from CRM problematically:

ExportTranslationRequest req = new ExportTranslationRequest();
req.SolutionName = "Final Solution";
ExportTranslationResponse resp = (ExportTranslationResponse)service.Execute(req);
String outputDir = @"C:\CRMTranslaions\";
byte[] exportXml = resp.ExportTranslationFile;
string filename = "CRMTranslations" + ".zip";
File.WriteAllBytes(outputDir + filename, exportXml);
Console.WriteLine("Translations exported to {0}.", outputDir + filename);

Could not load file or assembly ‘Microsoft.Xrm.Client, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ or one of its dependencies. The system cannot find the file specified.

To fix this error, do the following steps.

  • copy the file from the following folder "SDK\Bin"
  • Paste if in the following folder "program files\Microsoft Dynamics CRM\CRMWeb\bin"

Note: you can download the SDK  from the following link

Disable Caching for Organization Service In CRM 2011/2013/2015

MS CRM has caching feature but sometimes you want to disable it to get the latest updates,two ways to disable caching
First way - Configuration

Add the following configuration block to the config file of your application


<sectionname="microsoft.xrm.client"type="Microsoft.Xrm.Client.Configuration.CrmSection, Microsoft.Xrm.Client"/>




<addname="Xrm"type="Xrm.XrmServiceContext, Xrm"serviceName="Xrm"/>



<addname="Xrm"type="Microsoft.Xrm.Client.Services.OrganizationService, Microsoft.Xrm.Client"/>


Second Way - Pragmatically


How to solve : A proxy type with the name account has been defined by another assembly

The problem is actually with WCF attempting to deserialize the server response and not being able to identify the correct type. The best method to sort this issue is to pass in the current assembly using Assembly.GetExecutingAssembly() to the ProxyTypesBehavior() while creating the proxy like so

using (serviceProxy = new OrganizationServiceProxy(config.OrganizationUri,
// This statement is required to enable early-bound type support.
serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior(Assembly.GetExecutingAssembly()));

XRM Speed Builder for MS CRM

XRM speedy Tool allows migrating existing applications to CRM in a quick way by providing the following :
- Creates custom entities from SQL Server database tables
- Creates attributes from fields from database table fields
- Puts fields on forms.
Thanks to Jason Lattimer for this perfect tool.

Perform left outer join using Fetch XML in MS CRM

This illustration shows you how to use FetchXML queries to perform left outer join.

The following query shows how to query accounts having no leads

<fetch mapping='logical'>
<entity name='account'>
<attribute name='name'/>
<link-entity name='lead' from='leadid' to='originatingleadid' link-type='outer'/>
<filter operator='and'>
<condition entityname='lead' attribute='leadid' operator='null'/>