DataServiceContext Class
The DataServiceContext represents the runtime context of the data service.
Inheritance Hierarchy
System.Object
System.Data.Services.Client.DataServiceContext
Namespace: System.Data.Services.Client
Assembly: Microsoft.Data.Services.Client (in Microsoft.Data.Services.Client.dll)
Syntax
'Declaration
Public Class DataServiceContext
'Usage
Dim instance As DataServiceContext
public class DataServiceContext
public ref class DataServiceContext
type DataServiceContext = class end
public class DataServiceContext
The DataServiceContext type exposes the following members.
Constructors
Name | Description | |
---|---|---|
DataServiceContext() | Initializes a new instance of the DataServiceContext class. | |
DataServiceContext(Uri) | Initializes a new instance of the DataServiceContext class with the specified serviceRoot. | |
DataServiceContext(Uri, DataServiceProtocolVersion) | Initializes a new instance of the DataServiceContext class with the specified serviceRoot and targeting the specific maxProtocolVersion. |
Top
Properties
Name | Description | |
---|---|---|
AddAndUpdateResponsePreference | Gets or sets whether the client requests that the data service return entity data in the response message to a change request. | |
ApplyingChanges | Gets a value that indicates whether the DataServiceContext is currently applying changes to tracked objects. | |
BaseUri | Gets the absolute URI identifying the root of the target data service. | |
Credentials | Gets or sets the authentication information that is used by each query created by using the DataServiceContext object. | |
DataNamespace | Obsolete. Gets or sets the XML namespace for data items, not metadata items, of an Atom payload. | |
Entities | Gets a list of all the resources currently being tracked by the DataServiceContext. | |
HttpStack | Gets a value that indicates the type of HTTP implementation to use when accessing the data service.Supported only by the WCF Data Services 5.0 client for Silverlight. | |
IgnoreMissingProperties | Gets or sets whether the properties read from the type must be mapped to properties on the client-side type. | |
IgnoreResourceNotFoundException | Gets or sets whether an exception is raised when a 404 error (resource not found) is returned by the data service. | |
Links | Gets the collection of all associations or links currently being tracked by the DataServiceContext object. | |
MaxProtocolVersion | Gets the maximum version of the Open Data Protocol (OData) that the client is allowed to use. | |
MergeOption | Gets or sets the synchronization option for receiving entities from a data service. | |
ResolveEntitySet | Gets or sets the delegate method that is used to resolve the entity set URI when the value cannot be determined from an edit-link or self-link URI. | |
ResolveName | Gets or sets a function to override the default type resolution strategy used by the client library when you send entities to a data service. | |
ResolveType | Gets or sets a function that is used to override the default type resolution option that is used by the client library when receiving entities from a data service. | |
SaveChangesDefaultOptions | Gets or sets the SaveChangesOptions values that are used by the SaveChanges method. | |
Timeout | Gets or sets the time-out option (in seconds) that is used for the underlying HTTP request to the data service. | |
TypeScheme | Obsolete. Gets or sets the URI used to indicate what type scheme is used by the service. | |
UseDefaultCredentials | Gets or sets whether default credentials are used to authenticate requests to the data service. Supported only by the WCF Data Services 5.0 client for Silverlight. | |
UsePostTunneling | Gets or sets a Boolean value that indicates whether to use post tunneling. |
Top
Methods
Name | Description | |
---|---|---|
AddLink | Adds the specified link to the set of objects the DataServiceContext is tracking. | |
AddObject | Adds the specified object to the set of objects that the DataServiceContext is tracking. | |
AddRelatedObject | Adds a related object to the context and creates the link that defines the relationship between the two objects in a single request. | |
AttachLink | Notifies the DataServiceContext to start tracking the specified link that defines a relationship between entity objects. | |
AttachTo(String, Object) | Notifies the DataServiceContext to start tracking the specified resource and supplies the location of the resource within the specified resource set. | |
AttachTo(String, Object, String) | Notifies the DataServiceContext to start tracking the specified resource and supplies the location of the resource in the specified resource set. | |
BeginExecute(Uri, AsyncCallback, Object, String, array<OperationParameter[]) | Asynchronously sends a request to the data service to execute a specific URI. | |
BeginExecute<TElement>(Uri, AsyncCallback, Object) | Asynchronously sends the request so that this call does not block processing while waiting for the results from the service. | |
BeginExecute<T>(DataServiceQueryContinuation<T>, AsyncCallback, Object) | Asynchronously sends a request to the data service to retrieve the next page of data in a paged query result. | |
BeginExecute<TElement>(Uri, AsyncCallback, Object, String, Boolean, array<OperationParameter[]) | Asynchronously sends a request to the data service to execute a specific URI. | |
BeginExecuteBatch | Asynchronously submits a group of queries as a batch to the data service. | |
BeginGetReadStream(Object, DataServiceRequestArgs, AsyncCallback, Object) | Asynchronously gets the binary data stream that belongs to the specified entity, by using the specified message headers. | |
BeginGetReadStream(Object, String, DataServiceRequestArgs, AsyncCallback, Object) | Asynchronously gets a named binary data stream that belongs to the specified entity, by using the specified message headers. | |
BeginLoadProperty(Object, String, AsyncCallback, Object) | Asynchronously loads the value of the specified property from the data service. | |
BeginLoadProperty(Object, String, DataServiceQueryContinuation, AsyncCallback, Object) | Asynchronously loads the next page of related entities from the data service by using the supplied query continuation object. | |
BeginLoadProperty(Object, String, Uri, AsyncCallback, Object) | Asynchronously loads a page of related entities from the data service by using the supplied next link URI. | |
BeginSaveChanges(AsyncCallback, Object) | Asynchronously submits the pending changes to the data service collected by the DataServiceContext since the last time changes were saved. | |
BeginSaveChanges(SaveChangesOptions, AsyncCallback, Object) | Asynchronously submits the pending changes to the data service collected by the DataServiceContext since the last time changes were saved. | |
CancelRequest | Attempts to cancel the operation that is associated with the supplied IAsyncResult object. | |
CreateQuery<T> | Creates a data service query for data of a specified generic type. | |
DeleteLink | Changes the state of the link to deleted in the list of links being tracked by the DataServiceContext. | |
DeleteObject | Changes the state of the specified object to be deleted in the DataServiceContext. | |
Detach | Removes the entity from the list of entities that the DataServiceContext is tracking. | |
DetachLink | Removes the specified link from the list of links being tracked by the DataServiceContext. | |
EndExecute(IAsyncResult) | Called to complete the BeginExecute. | |
EndExecute<TElement>(IAsyncResult) | Called to complete the BeginExecute. | |
EndExecuteBatch | Called to complete the BeginExecuteBatch. | |
EndGetReadStream | Called to complete the asynchronous operation of retrieving a binary data stream. | |
EndLoadProperty | Called to complete the BeginLoadProperty operation. | |
EndSaveChanges | Called to complete the BeginSaveChanges operation. | |
Equals | (Inherited from Object.) | |
Execute(Uri, String, array<OperationParameter[]) | Sends a request to the data service to execute a specific URI by using a specific HTTP method.Not supported by the WCF Data Services 5.0 client for Silverlight. | |
Execute<TElement>(Uri) | Sends a request to the data service to execute a specific URI.Not supported by the WCF Data Services 5.0 client for Silverlight. | |
Execute<T>(DataServiceQueryContinuation<T>) | Sends a request to the data service to retrieve the next page of data in a paged query result.Not supported by the WCF Data Services 5.0 client for Silverlight. | |
Execute<TElement>(Uri, String, Boolean, array<OperationParameter[]) | Sends a request to the data service to execute a specific URI by using a specific HTTP method.Not supported by the WCF Data Services 5.0 client for Silverlight. | |
ExecuteBatch | Synchronously submits a group of queries as a batch to the data service.Not supported by the WCF Data Services 5.0 client for Silverlight. | |
Finalize | (Inherited from Object.) | |
GetEntityDescriptor | Gets the EntityDescriptor for the supplied entity object. | |
GetHashCode | (Inherited from Object.) | |
GetLinkDescriptor | Gets the LinkDescriptor for a specific link that defines the relationship between two entities. | |
GetMetadataUri | Gets a URI of the location of .edmx metadata. | |
GetReadStream(Object) | Gets the binary data stream that belongs to the specified entity.Not supported by the WCF Data Services 5.0 client for Silverlight. | |
GetReadStream(Object, DataServiceRequestArgs) | Gets binary data stream for the specified entity by using the specified message headers.Not supported by the WCF Data Services 5.0 client for Silverlight. | |
GetReadStream(Object, String) | Gets the binary data stream that belongs to the specified entity, by using the specified Content-Type message header.Not supported by the WCF Data Services 5.0 client for Silverlight. | |
GetReadStream(Object, String, DataServiceRequestArgs) | Gets a named binary data stream that belongs to the specified entity, by using the specified Content-Type message header.Not supported by the WCF Data Services 5.0 client for Silverlight. | |
GetReadStreamUri(Object) | Gets the URI that is used to return a binary data stream. | |
GetReadStreamUri(Object, String) | Gets the URI that is used to return a named binary data stream. | |
GetType | (Inherited from Object.) | |
LoadProperty(Object, String) | Loads deferred content for a specified property from the data service.Not supported by the WCF Data Services 5.0 client for Silverlight. | |
LoadProperty(Object, String, DataServiceQueryContinuation) | Loads the next page of related entities from the data service by using the supplied query continuation object.Not supported by the WCF Data Services 5.0 client for Silverlight. | |
LoadProperty(Object, String, Uri) | Loads a page of related entities by using the supplied next link URI.Not supported by the WCF Data Services 5.0 client for Silverlight. | |
LoadProperty<T>(Object, String, DataServiceQueryContinuation<T>) | Loads the next page of related entities from the data service by using the supplied generic query continuation object.Not supported by the WCF Data Services 5.0 client for Silverlight. | |
MemberwiseClone | (Inherited from Object.) | |
SaveChanges() | Saves the changes that the DataServiceContext is tracking to storage.Not supported by the WCF Data Services 5.0 client for Silverlight. | |
SaveChanges(SaveChangesOptions) | Saves the changes that the DataServiceContext is tracking to storage.Not supported by the WCF Data Services 5.0 client for Silverlight. | |
SetLink | Notifies the DataServiceContext that a new link exists between the objects specified and that the link is represented by the property specified by the sourceProperty parameter. | |
SetSaveStream(Object, Stream, Boolean, DataServiceRequestArgs) | Sets a binary data stream for the specified entity, with the specified headers in the request message. | |
SetSaveStream(Object, Stream, Boolean, String, String) | Sets a binary data stream that belongs to the specified entity, with the specified Content-Type and Slug headers in the request message. | |
SetSaveStream(Object, String, Stream, Boolean, DataServiceRequestArgs) | Sets a named binary data stream that belongs to the specified entity, with the specified headers in the request message. | |
SetSaveStream(Object, String, Stream, Boolean, String) | Sets a binary data stream for the specified entity. | |
ToString | (Inherited from Object.) | |
TryGetEntity<TEntity> | Test retrieval of an entity being tracked by the DataServiceContext by reference to the URI of the entity. | |
TryGetUri | Retrieves the canonical URI associated with the specified entity, if available. | |
UpdateObject | Changes the state of the specified object in the DataServiceContext to Modified. |
Top
Events
Name | Description | |
---|---|---|
ReadingEntity | Occurs after entity data has been completely read into the entity object. | |
SendingRequest | Occurs when a new HttpWebRequest has been created. | |
SendingRequest2 | Occurs when a new HttpWebRequest has been created. | |
WritingEntity | Occurs after an entity has been fully serialized into XML in a request message. |
Top
Remarks
WCF 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.
Examples
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 WCF Data Services?quickstart.
' Create the DataServiceContext using the service URI.
Dim context = New NorthwindEntities(svcUri)
' Define a new query for Customers.
Dim query As DataServiceQuery(Of Customer) = context.Customers
Try
' Enumerate over the query result, which is executed implicitly.
For Each customer As Customer In query
Console.WriteLine("Customer Name: {0}", customer.CompanyName)
Next
Catch ex As DataServiceQueryException
Throw New ApplicationException( _
"An error occurred during query execution.", ex)
End Try
// Create the DataServiceContext using the service URI.
NorthwindEntities context = new NorthwindEntities(svcUri);
// Define a new query for Customers.
DataServiceQuery<Customer> query = context.Customers;
try
{
// Enumerate over the query result, which is executed implicitly.
foreach (Customer customer in query)
{
Console.WriteLine("Customer Name: {0}", customer.CompanyName);
}
}
catch (DataServiceQueryException ex)
{
throw new ApplicationException(
"An error occurred during query execution.", ex);
}
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also
Reference
System.Data.Services.Client Namespace