Monday, June 29, 2015

Early Binding and Late Binding In MS CRM 2015

Late Binding

In Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM Online 2015 Update, you can use the Entity class when you work with entities. 
When initialized, the Entity class contains the logical name of an entity and a property-bag array of the entity’s attributes. 
This lets you use late binding so that you can work with types such as custom entities and custom attributes that weren’t available when your application was compiled. 
The key difference between early and late binding involves type conversion. While early binding provides compile-time checking of all types so that no implicit casts occur, late binding checks types only when the object is created or an action is performed on the type. 
The Entity class requires types to be explicitly specified to prevent implicit casts.

//Get the Value from optionset.

int val = ((OptionSetValue)account.Attributes["schemaname"].Value;

// Get the Text from OptionSet

String optiontext=account.FormattedValue["schemaname"].ToString();

// Set Value to the optionset

account.Attributes["schemaname"] = new OptionSetValue(1000);

// Get the lookup value

Guid ID = (EntityReference)account.Attributes["schemaname"].Id;

// Set lookup value

account.Attributes["schemaname"] = new EntityReference("contact",Guid);

Early Binding

The examples shown previously used late binding. When using late binding, accessing and using the Organization Service is difficult and you need to explicitly type both the entity and attribute’s names.
This makes the code cumbersome to write, and sometimes prone to errors.
Instead of using late binding, you can use early binding which provides IntelliSense support and better code development and use of .NET technologies such as the .NET Framework Language-Integrated Query (LinQ). 
To use early binding, you must generate the entity classes by using the code
generation tool called CrmSvcUtil.exe, a console application that you can find in the SDK\bin folder of the CRM 2013 SDK.
Here is an example of calling this tool:
Click here to view code image
CrmSvcUtil.exe /url:http://columbuscrm/demo1/XRMServices/2011...
/out:GeneratedCode.cs /username:bill /password:p@ssword!

No comments:

Post a Comment

Get files of last hour in Azure Data Factory

  Case I have a Data Factory pipeline that should run each hour and collect all new files added to the data lake since the last run. What is...