Build Complex Queries
[Applies to: Microsoft Dynamics CRM 4.0]
Find the latest SDK documentation: CRM 2015 SDK
This section provides some general advice on how to approach more complex queries. It is best to start with a simplified version of the desired query. This might include the basic join and where clauses that will keep the resulting data manageable. Gradually build from this starter query. If unexpected results appear, it can be useful to translate the query to FetchXML and check for misplaced entities or invalid clauses.
If you cross the line where the query goes beyond the limitations of the query provider, try stepping back to the last working query and force evaluation by calling the ToList() method. This delegates query processing from the Microsoft Dynamics CRM query provider into LINQ to Objects at the point that ToList() is called. Once you are working with LINQ to Objects, the full capabilities of where clause expressions, aggregation, and merging multiple entity types is possible.
var totalCostAggregate = ( from marketingList in crm.lists select marketingList.cost).ToList().Sum();
- Translate a LINQ Query to FetchXML
- Parts of the Query
- Use Dynamic Entity with LINQ Queries and the CrmDataContext
© 2010 Microsoft Corporation. All rights reserved.