Thursday, March 19, 2009


LINQ to CRM is one of Microsoft’s latest additions to the .Net 3.5 Framework Library. This library provides a uniform method of access to different types of entities, through a query language very similar to SQL. To learn more, see MSDN’s reference to LINQ to Entities and TechTarget’s LINQ Learning Guide.

I’m very excited to talk about the new LINQ to CRM libraries available recently. Say you need to retrieve an Account Number, given the Account Name…

Using the traditional webservice methods:
ColumnSet cols = new ColumnSet();
cols.AddColumns(new string[] {"accountnumber"});

query = new QueryByAttribute();
query.ColumnSet = cols;
query.EntityName = "account";
query.Attributes = new string[] {"name"};
query.Values = new string[] {"Microsoft Dynamics CRM"};

RetrieveMultipleRequest req = new RetrieveMultipleRequest();
req.Query = query;
req.ReturnDynamicEntities = true;

RetrieveMultipleResponse resp = oService.Execute(req) as RetrieveMultipleResponse;
BusinessEntityCollection becMultipleRecords = resp.BusinessEntityCollection;
if (deSalesOrder.Properties.Contains("accountnumber"))
//And So On
//And So Forth

Using LINQ to SQL:
var accounts = (from a in context.Accounts
where a.Name.Equals("Microsoft Dynamics CRM")
select a).ToList();
LINQ2CRM.Account acc = (Account)accounts.First();
Response.Write("Account name = " + acc.Name.ToString());

The choice seems obvious to me, but I’ll try to contain myself. Though the available LINQ to CRM libraries already address select and update of data, there are still shortfalls. Functionality such as Assign and Set Status are still not available and need to be performed via the traditional methods. But judging by progress so far, I’m sure it won’t be long.

LINQ to CRM on CodePlex is a (Beta) community library available free for download and evaluation. I’m always a supporter of free and community based software, so I highly recommend support of this project. Ofcourse being in Beta, this is work in progress and I would not recommend use of this assembly commercially.

XrmLinq is a commercially available package. This is a much more complete and stable library. Installation and use is remarkably simple and functionally fairly complete. License fee is based on per deployment which makes it a little more costly than I would prefer but is available for free to CRM providers for development purposes. A subset of this library and source code is available on CodePlex for any curioustechies.

No comments: