Race horses

As a Microsoft Dynamics CRM developer I use several programming model to achieve my goals. One of these is early-bounding entity data model. Which is th ebest method? Which is the fastest? I am not sure! Some say that early binding is the fastest, other says that late-binding is. Is there any difference?

Since Early-bound is just a wrapper over the late bound entity class, and contains all the functionality, it  has a faster runtime than late bound. But, as I experienced, this difference is extremly small and I would like to refer to Eric Lippert’s article:

Early-bound and late-bound are similar than two race horses. Which is the faster? I probably cannot sensible answer that question:

„If you have two horses and you want to know which of the two is the faster then race your horses. Don’t write short descriptions of the horses, post them on the Internet, and ask random strangers to guess which is faster! Even if by sheer chance you got an accurate answer, how would you have any confidence in its accuracy? You can easily and accurately discover which of two programs is faster by running both yourself and measuring them with a stopwatch.”

How to start?

We can use the CrmSvcUtil.exe tool for use with Microsoft Dynamics CRM 2011/2013/2015 and Microsoft Dynamics CRM Online 2011/2013/2015. This tool genarates early-bound .NET Framework classes that represent the entity data model used by Microsoft Dynamics CRM. You can find this tool in the SDK package in the SDK\Bin folder,

The CrmSvcUtil.exe tool creates a Microsoft Visual C# or Microsoft Visual Basic .NET output file containing strongly-typed classes for entities in your organization. Each time a change is made to a CRM entity, the entity type definitions will need to be updated (in case you want to use a new property or entity, or you have removed a property or entity that you currenly use.

This tool is also able to genarate a class derived from the OrganizationServiceContext class that acts as an entity container in the entity data model.

The tool takes several parameters that can determine the the contents of the file that is created. The parameters can be passed in from the command line when you run the tool, or you can use configuration file.
CrmSvcUtil

  • The configuration file MUST BE in the same folder as the CrmSvcUtil.exe.
  • The file uses the standard key/value pairs is appSettings section.
  • The values in the command line will overwrites any key/value pairs in the application configuration file.
<appSettings>
  <add key="o" value="CrmProxy.cs"/>
  <add key="d" value="mydomain"/>
</appSettings>

Other way to generate Early-bound classes is using CRM Early Bound Generator. You can download from CodePlex site,  here.

CrmSvcUtil2

This project is plugin for XrmToolBox. This tool is able to extend and automate the creation of Early-Bound classes.

Features:

  • We can generate Enums for the OptionSet
  • OptionSets can be sorted alphabetically.
  • The System.Diagnostics.DebuggerStepThrough code attributes can be appended to all code.
  • OptionSetEnum properties can be generated for each OptionSet property of every class.
  • Specific Entities are allowed to not be generated.
  • Specific OptionSets are allowed to not be generated.
  • The tool can generate a single file per Entity, rather than a big file.
  • The tool can generate a single file per OptionSet.
  • The tool can generate a single file per Action.
  • The tool will automatically check out of any generated files from Team Foundation Server.
  • The tool allows for using the Microsoft.Xrm.Client.CrmOrganizationServiceContext instead of using the OrganizationServiceContext for the base class of the ServiceContext