This documentation is archived and is not being maintained.

DataServiceContext Class

The DataServiceContext represents the runtime context of the data service.

Namespace:  System.Data.Services.Client
Assembly:  System.Data.Services.Client (in System.Data.Services.Client.dll)

public class DataServiceContext

This topic describes new functionality in ADO.NET Data Services that is available as an update to the .NET Framework version 3.5 Service Pack 1. You can download and install the update from the Microsoft Download Center.

ADO.NET Data Services are stateless, but the DataServiceContext is not. State on the client is maintained between interactions in order to support features such as update management. This class, and the DataServiceQuery class that represents a particular HTTP request to a data service, are the two main classes in the client library.

The following example shows how to use the DataServiceContext generated by the Add Service Reference tool to implicitly execute a query against the Northwind data service that returns all customers. The URI of the requested Customers entity set is determined automatically by the context. The query is executed implicitly when the enumeration occurs. The Northwind data service is created when you complete the ADO.NET Data Services quickstart.

// Create the DataServiceContext using the service URI.
NorthwindEntities context = new NorthwindEntities(svcUri);

// Define a new query for Customers.
DataServiceQuery<Customers> query = context.Customers;

    // Enumerate over the query result, which is executed implicitly. 
    foreach (Customers customer in query)
        Console.WriteLine("Customer Name: {0}", customer.CompanyName);
catch (Exception ex)
    throw new ApplicationException(
        "An error occurred during query execution.", ex);


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5 SP1