UPDATE: There’s a known issue with the LINQPad Plugin for Microsoft Dynamics CRM 2011 and Office 365 authentication. I cover a workaround here.
Using FetchXML is necessary in many situations with CRM 2011. Using FetchXML becomes even more necessary if you are taking a “design for online” approach to solution building. I’m a big believer that everyone should approach solution design this way because then your solution will truly be portable between CRM Online and CRM OnPrem (i.e. the CRM you install yourself). Typically, the need for FetchXML shows up first when you are building custom SQL Server Reporting Services (SSRS) reports. That’s because FetchXML based reports are the only option in CRM Online. I mentioned in my CRM Online myth busters post that I prefer to use LINQPad + LINQPad Plugin for Microsoft Dynamics CRM 2011 to compose my queries, then convert them to FetchXML. This post is a walkthrough of how I do it. I got the inspiration for the code sample I will present from the following two samples:
Place the code I provide you below within the MyExtensions class under the comment that says to “write custom extension methods here.” Here’s what the file looks like before you’ve added anything to it:
Here’s the code you need to add under the comment:
In addition to adding the code, you need to add references to a few .NET assemblies. From within the “My Extensions” file, press the F4 key to bring up the properties dialog. Add references to the following assemblies (note your location for CRM 2011 SDK assemblies might be different):
Now, once you’ve written and executed the query that you want in LINQPad:
…you can then wrap the query in parenthesis and call the ToFetchXml() extension method to get the FetchXML:
BAM! This approach has really helped me be productive in composing FetchXML queries. I use this mostly when writing SSRS reports, but also find it useful for other occasions where I need to use FetchXML. See the LINQ Limitations section of the Use LINQ to Construct a Query documentation for more details.