Building Queries

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

A query expression is used to programmatically build a query that contains data filters and search conditions that define the scope of a database search. A query expression is used for single-object searches, for example, to search for all accounts that match certain search criteria. A query expression is a strong typed (object based) approach to building queries that can be executed. The QueryBase class is the base class for query expressions. There are two derived classes: QueryExpression and QueryByAttribute. The QueryExpression class supports complex queries. The QueryByAttribute class is a simple means to search for entities where attributes match specified values.

To save a query, you can convert it to Fetch by using the QueryExpressionToFetchXml message and save it as a saved view by using the userquery entity.

Query expressions are used in methods that retrieve more than one entity instance such as the RetrieveMultiple method and in messages that perform an operation on a result set specified by a query expression such as the BulkDelete message.

Another way to build queries is to use FetchXML, the proprietary Microsoft Dynamics CRM query language.

In This Section

Messages that Use Query Expression

Lists all messages that use a query expression.

Using the QueryByAttribute Class

Learn to use the QueryByAttribute class to specify a simple query.

Using the QueryExpression Class

Discover the QueryExpression class to specify a more complex query.

Using the ColumnSet Class

Describes how to use the ColumnSet class to specify which columns to return from a query.

Using the ConditionExpression Class

Contains information about the ConditionExpression class to specify a condition.

Using the FilterExpression Class

Learn to use the FilterExpression class to specify a complex filter for a query.

Testing for a Null Value

See how to test for a null value in a query.

Using Intersect Tables

Describes how to use intersect tables.

Using the Paging Cookie (PageInfo)

Determine how to use the paging cookie.

Using FetchXML

Describes how and when to use the FetchXML query language.

Using Count Aggregation in FetchXML

Describes the updated aggregation behavior using count.

Related Sections

Query Sample Code

Contains sample code that show how to create queries.

© 2010 Microsoft Corporation. All rights reserved.