Hoping someone could shed some light from a performance standpoint on using OrganizationServiceContext.CreateQuery
vs using FetchXML
(or QueryExpression
).
I have made extensive use of LINQ
but am new to CRM. CreateQuery
seems like a good fit for my skill set but I wonder about performance in the end.
I realize that straight up
var result = from e in orgContext.CreateQuery("xyz_myentity")
where e["email"] == "[email protected]"
select e;
will return all attributes for xyz_myentity
, but I can't seem to find any documentation for the LINQ provider that sits on top of CRM. Will the using an anonymous type limit attributes returned from SQL / CRM? Or is the magic being done "client" side after the full set of data is returned from the server? Is the SQL query for all attributes and then is the LINQ provider building the anonymous type on top of that?
var result = from e in orgContext.CreateQuery("xyz_myentity")
where e["email"] == "[email protected]"
select new { Name=e["xyz_name"] };
Are there any other considerations related to the introduction of the OrganizationServiceContext
?
LINQ for CRM is built on top of the QueryExpression
and therefore has pretty much the same limitations. It is implemented client-side in the Microsoft.Xrm.Sdk library. The library sends QueryExpression
requests to the CRM web service.
LINQ adds an abstraction layer to the query stack (LINQ -> QueryExpression -> SQL), so you can expect a small performance hit.
FetchXML is the oldest technique available for querying CRM. Microsoft states it is slightly less performant on the server. Writing FetchXml queries comes down to constructing XML messages, so in general the programming experience is poor.
The OrganizationServiceContext
is required for processing LINQ queries; it is an object capable of tracking changes to data objects. It is known to have some issues and, again, it comes with a cost. E.g. tracking large amounts of data is not advisable.
When I have to choose between LINQ and QueryExpression
I still favour the latter. It's the most light-weight technology when you need to query CRM and with the help of a few extension methods the programming experience is OK.
(Note: CRM 2016 adds a new querying method using Web API.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With