How to use Early Binding and LINQ to query entity details in Dynamics CRM 2011

Early Binding
The CRMSvcUtil can generate the LINQ Service Context by providing the optional tag:
/serviceContextName:CrmDataContext

The LINQ Service Context that is produced by taking this approach is a gateway to the work with the LINQ provider. When the CRMDataContext class is instantiated, an instance of the Organization Service will be passed:

var = new CrmDataContext(orgServiceInstance)

This produces a LINQ context that code can work with. This context has public, queryable properties for each entity set.
Querying Data with LINQ
Similar to other querying techniques such as QueryExpression, FetchXML, and the use of Filtered Views, LINQ can be used to query data within Microsoft Dynamics CRM 2011.

OrganizationServiceContext orgContext = new OrganizationServiceContext(_service);
 var queryx = from c in orgContext.ContactSet
 join a in orgContext.AccountSet
 on c.ContactId equals a.PrimaryContactId
 select new { contact_name = c.Fullname, account_name = a.Name };
 foreach(var c in queryx)
 {
 this.comboBox2.Items.Add(c.contact_name);
 }

One of the key aspects of LINQ which differentiates it from the two other querying methods is that it can perform record creation, updating, and deleting.

This entry was posted in MS CRM 2011 and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *