The DataServiceQuery<TElement> generic class represents a query that returns a collection of zero or more entity type instances. A data service query always belongs to an existing data service context. This context maintains the service URI and metadata information that is required to compose and execute the query.
When you use the Add Service Reference dialog to add a data service to a .NET Framework-based client application, an entity container class is created that inherits from the DataServiceContext class. This class includes properties that return typed DataServiceQuery<TElement> instances. There is one property for each entity set that the data service exposes. These properties make it easier to create an instance of a typed DataServiceQuery<TElement>.
A query is executed in the following scenarios:
When results are enumerated implicitly, such as:
When a property on the DataServiceContext that represents and entity set is enumerated, such as during a foreach (C#) or For Each (Visual Basic) loop.
When the query is assigned to a List collection.
When the Execute or BeginExecute method is explicitly called.
When a LINQ query execution operator, such as First or Single is called.
The following query, when it is executed, returns all Customers entities in the Northwind data service:
' Define a new query for Customers.
Dim query As DataServiceQuery(Of Customer) = context.Customers
For more information, see How to: Execute Data Service Queries (WCF Data Services).
The WCF Data Services client supports queries for late-bound objects, such as when you use the dynamic type in C#. However, for performance reasons you should always compose strongly-typed queries against the data service. The Tuple type and dynamic objects are not supported by the client.