The Microsoft Dynamics CRM 2011 Software Development Kit ships with a tool (CrmSvcUtil) which can automatically generate helper classes to make it easier to work with your CRM entities and their attributes. Developers can take advantage of type checking at compile time and intellisense for entity, attribute and relationship definitions. In this post, we will look at some simple examples on how to perform CRUD operations using early binding.
Generating the Helper Class
In the command prompt, navigate to <installation directory>\Microsoft Dynamics CRM 2011 SDK\sdk\bin. Enter crmsvcutil.exe to run the application and you will see the available parameters to use in order to successfully generate a helper class to use in your CRM project.
/url: A URL or path to the SDK endpoint to contact for metadata
/o: The filename for the generated helper class
/u: The username to authenticate against the CRM server
/p: The password to authenticate against the CRM server
/d: The domain to authenticate against the CRM server
Because the generated entity classes inherit from the Entity class, developers can perform CRUD operations as they normally would if using late binding. The only difference is that objects need to be casted to the correct types.
Example – Creating Records
The image below shows how developers can make use of intellisense when creating an Account record. We can work with the Account entity without having to know each and every attribute that is available.
Like late binding, we can use the Create method of the IOrganizationService to create the Account in CRM.
Intellisense is also available for custom entities, but they are prefixed based on the publisher set up in your CRM implementation. For example:
Example – Retrieving Records
The following example shows how to use the Retrieve method to retrieve an Account.
Example – Updating Records
The following example shows how to update the telephone2 field for an Account.
In my next post, I will take you through some coding examples using late binding in CRM 2011.