Using Linq in CRM 4.0

From LinkedIn

Has anyone used Linq to CRM query provider in a production environment yet?
Linq to CRM:
I also just found out that Microsoft has released their own Linq support as part of the new CRM SDK: anyone used this Microsoft supported Linq support yet? What does everyone think of it?Tim Dutcher • The Customer Portal Accelerator (available on codeplex) uses Linq for querying CRM. The code is elegant, easy to understand, and seems to perform well. I wouldn’t hesitate to use Linq — you’ll benefit from its consistent syntax and you’ll be able to use your skills when querying SQL, XML, etc.


David Vidmar • I’m using it in my latest Dynamics CRM 4.0 project and I have to say it’s great. Code is much cleaner and developing queryiest is way faster than using FetchXML. So far I haven’t had any unpleasant surprises, but you could also fall-back to classic method and combine both. So, thumbs up from me.

Pedram Soheil • Based on what I have heard CRM Linq queries with Microsoft supported provider ultimately map down to a QueryExpression. This means that the same limitation such as not being able to select from joined entities apply to the Linq provider. Has this been a big issue for either of you and are you aware of any other limitations?

Himanshu Chauhan • Guys if we are querying with join using linq can we get the attribute values of both entities. if yes then how ? Please help……

Pedram Soheil • @Himanshu – That is basically what I was saying is not possible with the Linq support Microsoft has added.

Himanshu Chauhan • Thanx….

Eric Kalos • I could be wrong but I think the new SDK LINQ feature cannot be used in developing plug-ins.

Himanshu Chauhan • I am working on setstate message, like we can do with CRM servcie method is it possible to change the state code of an entity with new sdk developeer extension methods……?

Andy Schultz • Actually, you can return values from related entities. The old QueryExpression could as well, using the LinkEntity.
For the work I’ve been doing, the main benefit of the new Developer Extensions have been the ease of connecting to the services. You don’t have to download a WSDL that’s specific to a company’s organization, you don’t have to write different authentication code for CRM Online and On-premise. I think IFD impersonation is still out for now, but I’m thinking they’ll support that in the next release.The extensions can’t take an IPluginExecutionContext, so they don’t really help with plugins yet. 

Pedram Soheil • Thanks Andy. That’s a real shame about extensions not supporting Plug-in. That would have been my #1 use for them. Would be nice not to have to depend on a specific WSDL inside the plug-in!

Mark Kovalcson • For plug-ins, you use Dynamic Entities to get around specific web references.

Nick Murdock • I have just started playing with the xrm and LINQ functionality and have to say it is really good for the normal CRM stuff, would be even better if you could make use of the LINQ capabilities to use GROUP statements etc but there are work arounds for this.

Abison Mathew Jose • xRM and LINQ to CRM is all CRM developers were waiting to for long from Microsoft.
Even though it does not take IPluginExecutionContext, it takes workflow context.
I believe the we could modify the generated data context class with additional constructors which will accept ICrmService…

Varun Dewan • Hi, I have just started using LINQ to CRM. This definitely looks great. However, can anyone help me with building dynamic where clause ?

Greg Spross • Andy – can you point to an example of returning data from multiple entities using the Linq provider?

Pat Janes • Greg; you can return attributes from multiple entities by projecting the crm entity query into an object list by using .ToList().
I’m going by memory here, so until I get back into the office on Monday, excuse the inevitable typos, but something like:
var opportunity =
from o in XrmDataContext.opportunities.ToList()
join c in XrmDataContext.contacts on o.customerid.Value equals c.contactid
where o.opportunityid = new Guid(“{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}”)
select new
Title = o.title,
CustomerName = c.fullname
);Be aware, however, that the .ToList() operator causes immediate execution (ordinarily execution of the entire LINQ query is delayed until the resultant query object is first used; in this case, it means (as I understand it) that the entire set of opportunities is returned and whittled down by the predicate(s) in the where clause and/or join criteria.Depending on the size of your datasets, this could be quite a performance issue.


Andy Schultz • Hi Greg,
Here’s an example using the asynchronous calls in Silverlight over a WCF data service:
var query = (from profile in svc.systemusers.Expand(“user_opportunity”)
select profile) as DataServiceQuery<systemuser>;
query.BeginExecute(on_profilequery, query);
I think the “Expand” method is unique to WCF data service calls, but there are similar methods available in the standard data context. Have you just tried a standard join?

Greg Spross • Thanks. Yes, I’ve tried a standard join, but unless you ‘ToList’ the ‘from’ entity, you’ll get an error message stating something along the lines of not being able to select from more than one entity.

Greg Spross • The developer extensions documentation states that the cmrsvcutil will generate enumeration types for picklist values. Do I need to specify that somewhere in the command? I don’t see any generated enums in the class file that was generated.


2 Comments (+add yours?)

  1. Diego
    Feb 06, 2011 @ 21:03:41


    Do you know the answer of below Himanshu question? how is possible to activate/deactivate crm records using crmlinq?


    Himanshu Chauhan • I am working on setstate message, like we can do with CRM servcie method is it possible to change the state code of an entity with new sdk developeer extension methods……?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: