Bhoopathi

"Be Somebody Nobody Thought You could Be"

Wednesday, September 21

MS CRM: QueryExpression vs FetchExpression

MS CRMQueryExpression and FetchExpression in Dynamics CRM 2013


QueryExpression and FetchExpression are the classes in CRM SDK to retrieve the data from CRM DB. 
Both of them have similarities and differences.
Similarities:
  • Can query the CRM data by defining the columns, filter conditions
  • Can support Order BY on columns
  • Can link with child entities to retrieve the data
  • Can group the conditions in filter criteria by using GROUP AND / GROUP OR
  • Can query maximum 5000 records in a single run
  • Can use Paging cookie to retrieve more than 5000 records.
  • QueryExpression and FetchExpression both of them are used in methods that retrieve more than one record (RetrieveMultiple)
Differences:
Query ExpressionFetch Expression
We can’t easily understand the queryFetch query is very clear and readable compare to Query Expression
Aggregate operations are not supported.Can query the aggregate operation with FetchExpression like Count, sum, AVG, min and Max
 If we don’t specify the columnset, it will return only one “PrimaryKey” (GUID) column value If we don’t specify the <attribute> tag in FetchExpression, it will return all columns
Query Expression supports intellisense while writing a query. It will make developers job easy.Fetch Expression doesn’t supports intellisense. Manually we have to check the syntax of Fetch query. [We can download the fetch query from Advanced Find to avoid syntax errors]