When you're working with Dynamics CRM 2011 and you need to write plug-ins or other kinds of integration with .NET code you should make use of early binding. This gives you a context that contains a typed .NET representation of all your entities, relations...
Account entity = new Account ();
entity ["name"] = "My Account"; //loosely typed, late binding
entity.AccountNumber = "1234"; //strongly typed, early binding
Advantages of Early Binding are
1) You no longer have to work with magic strings when accessing attributes
2) Every property is typed the correct way. No need to cast attributes values anymore.
3) When entities or attributes are removed, renamed ... and you update your context your code won't build and you can fix each problem immediately. No more runtime errors.
4) Less bugs
5) Less manual work
Run the CrmSvcUtil.exe tool, with the Microsoft.Xrm.Client.CodeGeneration extension, to generate your entity classes and service contexts. The following is an example command to create a file called
Xrm.csthat points at an instance of Microsoft Dynamics CRM. Note that the Microsoft.Xrm.Client.CodeGeneration.dll file must be in the same directory as the CrmSvcUtil.exe file, or in the system GAC, when you run this command.
Download the CRM 2011 SDK to get Microsoft.Xrm.Client.CodeGeneration.dll and CrmSvcUtil.exe tool
Here are the steps to create early binding
1) Open the Command Prompt
2) Navigate to the SDK folder \sdk\bin
3) Run the command given below by changing the server name and organization name to your crm server name and organization name for which you want to create the early binding
CrmSvcUtil.exe /codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration" /out:Xrm.cs /url:http://CRMSERVERNAME/Organization NAME/XRMServices/2011/Organization.svc /domain:CONTOSO /username:administrator /password:pass@word1 /namespace:Xrm /serviceContextName:XrmServiceContext
It will create a xrm.cs file in your /sdk/bin folder