{"id":146,"date":"2010-04-09T12:55:00","date_gmt":"2010-04-09T07:25:00","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=146"},"modified":"2022-07-19T16:54:03","modified_gmt":"2022-07-19T11:24:03","slug":"fetchxml-vs-queryexpression","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2010\/04\/fetchxml-vs-queryexpression\/","title":{"rendered":"FetchXML v\/s QueryExpression"},"content":{"rendered":"<p>These are the two distinct ways that you can query CRM using CRM SDK to retrieve the required information.<br \/>\nQueryExpression is the mostly commonly used way for querying information in CRM. Probably because it uses the object oriented style of coding and so you have distinct classes for query, condition, columns etc. Youhave intellisense to support you when writing a query using QueryExpression.<br \/>\nHowever, it has its own limitations, one of them being the inability to provide a column of a linked entity to be returned as the query result. This perhaps because the Query Expression would return a dynamic entity or a strongly typed base entity and so it is unable to return columns of related entity.<br \/>\nSo you are not able to execute a query similar to the following<br \/>\nSelect Opportunity.name, Opportunity.estimatedvalue, Account.address1_city from FilteredOpportunity Opportunity<br \/>\nInner join<br \/>\nFilteredAccount Account on Opportunity.customerid = Account.accountis<br \/>\nWhere account.address1_country = \u201cUS\u201d<br \/>\nThis is however possible using FetchXML. FetchXML requires the query to be specified in XML format and the resultset is returned in XML format as well. This allows FetchXML to return related entity columns as well as this is just another node in the xml doc.<br \/>\nThe above select query can written as follows using FetchXML<br \/>\n&nbsp;<br \/>\nNote: CRM Views allow you to select columns of related entity to be displayed in the view\u2026 how do you think they do it??? FectchXML ofcourse. The query of the view created is stored as a FetchXML query in the SavedQuery entity.<br \/>\nCRM also provides the following messages to convert FetchXML to QueryExpression and vice versa.<br \/>\n&#8211; FetchXmlToQueryExpression : Converts from FetchXML to query expression.<br \/>\n&#8211; QueryExpressionToFetchXml : Converts from query expression to FetchXML.<br \/>\nNote again, if you are to convert a FetchXML that has select columns specified from related entity, to Query Expression, the related entity columns are not included in the QueryExpression columns list.<br \/>\nHope this helps to smart querying!!!<\/p>\n<h2 style=\"text-align: left;\"><div class=\"su-heading su-heading-style-default su-heading-align-center\" id=\"\" style=\"font-size:15px;margin-bottom:5px\"><div class=\"su-heading-inner\">70% of global 2000 companies apply gamification to improve productivity and returns!<\/div><\/div><\/h2>\n<p><em><strong><a href=\"https:\/\/bit.ly\/3RD4lYW\" target=\"_blank\" rel=\"noopener noreferrer\">Gamifics365<\/a> <\/strong>\u2013 Spin the magic of games within Microsoft Dynamics 365 CRM to improve user adoption, enhance productivity, and achieve company goals!<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>These are the two distinct ways that you can query CRM using CRM SDK to retrieve the required information. QueryExpression is the mostly commonly used way for querying information in CRM. Probably because it uses the object oriented style of coding and so you have distinct classes for query, condition, columns etc. Youhave intellisense to\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2010\/04\/fetchxml-vs-queryexpression\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[19],"tags":[794,799,1393],"class_list":["post-146","post","type-post","status-publish","format-standard","hentry","category-dynamics-crm","tag-fetch-xmlquery-expression","tag-fetchxmldynamics-crm","tag-queryexpression-vs-fetchxml"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=146"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/146\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}