Wednesday, December 30, 2009

Developing Your CRM/xRM Applications (Part - I)

There are THREE common methods to use CRM SDK in our extension projects. These are
  1. using CRM web reference, 
  2. using sdk assemblies files, and 
  3. using third-party tools. Each method has its own pros and cons. 

Using CRM web reference in extension project is very easy for implementation. All you need to do is just add web reference. But, if you have 300+ custom entities in your project, there will be some performance issues and memory leak problems occur in application development.

Using sdk assemblies files is good for application performance and stability. But, if you have many custom entities in your project, it will be a nightmare for all developers to do coding using dynamics entity approach.

The last method, using  third-party tools, will help you to a lot in your project implementation. They can provide easy way to implement dynamics entity approach  in your project. But, you have to spend a lot of money on license fees to use those third-party tools.

According to my experience, the second method is the best way for developing xRM applications. But you have to find out your own way to:
  1. generate entity wrapper class automatically
  2. convert wrapper class to dynamic entity, and
  3. implement library programs that support CRM SDK operations
How To Generate CRM Entity Wrapper Class Automatically

Today, I will show you a way to generate entity wrapper class using CRM Development Toolkit.

Software Requirements

1. VS .NET 2008 and .NET Framework 3.5 SP1
2. MS CRM 4.0 (either 32bit or 64bit)

Installation Steps

* Install VS 2008 and .NET Framework 3.5 SP1
* Install MS CRM 4.0 (either 32bit or 64bit)
* Install StyleCop V 4.3.2.1



Please do not forget to choose “MSBuild Integration Files” so that you can avoid following error message:



* Install CRM Explorer (Please refer to page 10 from "Customizing CRM by Using the Microsoft Dynamics CRM Developer Toolkit.pdf" for more detail)

Configuring CRM Solution Framework

1. The CRM Solution Framework is a suite of Visual Studio C# projects that are coupled with CRM Entity customizations and wrapped with extensible MSBuild–based developer builds and daily builds. The Framework contains several “pre-canned” projects for the typical tasks that are required of developers when undertaking most Enterprise-level CRM projects. Several of these projects have an inheritance model that affords simple and intuitive augmentation, which can significantly reduce the time required to “jump start” development of new projects.

2. Install CRM Solution Framework Template (Please refer to page 11 from “Customizing CRM by Using the Microsoft Dynamics CRM Developer Toolkit.pdf” for more detail)

setup.cmd [InstallDir] [Project Namespace] [Project Long Name] {Organization Name}




Configuring CRM Explorer

1.    The CRM Explorer complements the CRM Solution Framework, providing the project factories required to open and build the solution from within Visual Studio. The Explorer manifests as a window within Visual Studio 2008 and provides direct access to CRM for creating and editing business units, security roles, and most importantly, entities. The CRM Explorer is linked to the solution framework which enables it to intelligently place generated code into the relevant solution framework project.



2. Open VS 2008 and Configure Your CRM Explorer (Please refer to page 13 from “Customizing CRM by Using the Microsoft Dynamics CRM Developer Toolkit.pdf” for more detail)

Note: Default Port Number for CRM is 5555.



Generating Entity Wrapper Class



1. The EntityWrappers project supports a project factory that enables integration with CRM by means of examining the CRM metadata and generating code within the project to support the entities that exist. The core purpose of this project is to expose the CRM entities and their corresponding attributes as classes and properties respectively to enable code to be developed to interact with the entities.

2. For each CRM entity that the developer selects, two files will be created namely: [entityname].cs and [entityname].Attributes.cs (where [entityname] represents the name of the Entity within CRM). These files split a single class named after the entity through partial classing. The [entityname].Attributes.cs file contains all of the attributes present on the entity at the time of creation.

Note: A major reason for separating the attributes into a separate file is because of their volatility throughout the development phase. The [entityname].attributes.cs file should not be manually edited by the developer as it supports re-generation via the CRM Explorer.

3. Open CRM Solution Framework Solution from your installed directory. Right-click on entity you want to generate wrapper class from CRM Explorer. Then, click “Generate Wrapper Class”.



I will tell you how to convert entity wrapper class to dynamic entity, and how to implement library programs that support CRM SDK operations in my next posts. If you have questions about this post, either leave a comment or email me at thuta@thuta.info. Thanks.

Reference:
CRM Development Toolkit
Customizing CRM by Using the Microsoft Dynamics CRM Developer Toolkit
Developing Your CRM xRM Applications (Part - I)