Duration (Pacific Standard Time):
To (Pacific Standard Time):
Impact:
  • None
User Action:
  • None

DataServiceContext Class

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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)

System.Object
  System.Data.Services.Client.DataServiceContext

Public Class DataServiceContext
Name Description
System_CAPS_pubmethod DataServiceContext(Uri)

Initializes a new instance of the DataServiceContext class with the specified serviceRoot.

Name Description
System_CAPS_pubproperty ApplyingChanges

Gets a value that indicates whether the DataServiceContext is currently applying changes to tracked objects.

System_CAPS_pubproperty BaseUri

Gets the absolute URI identifying the root of the target data service.

System_CAPS_pubproperty Credentials

Gets or sets the authentication information that is used by each query created by using the DataServiceContext object.

System_CAPS_pubproperty DataNamespace

Gets or sets the XML namespace for data items, not metadata items, of an Atom payload.

System_CAPS_pubproperty Entities

Gets a list of all the resources currently being tracked by the DataServiceContext.

System_CAPS_pubproperty IgnoreMissingProperties

Gets or sets whether the properties read from the type must be mapped to properties on the client-side type.

System_CAPS_pubproperty IgnoreResourceNotFoundException

Gets or sets whether an exception is raised when a 404 error (resource not found) is returned by the data service.

System_CAPS_pubproperty Links

Gets the collection of all associations or links currently being tracked by the DataServiceContext object.

System_CAPS_pubproperty MergeOption

Gets or sets the synchronization option for receiving entities from a data service.

System_CAPS_pubproperty 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.

System_CAPS_pubproperty 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.

System_CAPS_pubproperty SaveChangesDefaultOptions

Gets or sets the SaveChangesOptions values that are used by the SaveChanges method.

System_CAPS_pubproperty Timeout

Gets or sets the time-out option that is used for the underlying HTTP request to the data service.

System_CAPS_pubproperty TypeScheme

Gets or sets the URI used to indicate what type scheme is used by the service.

System_CAPS_pubproperty UsePostTunneling

Gets or sets a Boolean value that indicates whether to use post tunneling.

Name Description
System_CAPS_pubmethod AddLink(Object, String, Object)

Adds the specified link to the set of objects the DataServiceContext is tracking.

System_CAPS_pubmethod AddObject(String, Object)

Adds the specified object to the set of objects that the DataServiceContext is tracking.

System_CAPS_pubmethod AddRelatedObject(Object, String, Object)

Adds a related object to the context and creates the link that defines the relationship between the two objects in a single request.

System_CAPS_pubmethod AttachLink(Object, String, Object)

Notifies the DataServiceContext to start tracking the specified link that defines a relationship between entity objects.

System_CAPS_pubmethod AttachTo(String, Object)

Notifies the DataServiceContext to start tracking the specified resource and supplies the location of the resource within the specified resource set.

System_CAPS_pubmethod 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.

System_CAPS_pubmethod 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.

System_CAPS_pubmethod 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.

System_CAPS_pubmethod BeginExecuteBatch(AsyncCallback, Object, DataServiceRequest[])

Asynchronously submits a group of queries as a batch to the data service.

System_CAPS_pubmethod BeginGetReadStream(Object, DataServiceRequestArgs, AsyncCallback, Object)

Asynchronously gets binary property data for the specified entity as a data stream along with the specified message headers.

System_CAPS_pubmethod BeginLoadProperty(Object, String, AsyncCallback, Object)

Asynchronously loads the value of the specified property from the data service.

System_CAPS_pubmethod 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.

System_CAPS_pubmethod BeginLoadProperty(Object, String, Uri, AsyncCallback, Object)

Asynchronously loads a page of related entities from the data service by using the supplied next link URI.

System_CAPS_pubmethod BeginSaveChanges(AsyncCallback, Object)

Asynchronously submits the pending changes to the data service collected by the DataServiceContext since the last time changes were saved.

System_CAPS_pubmethod BeginSaveChanges(SaveChangesOptions, AsyncCallback, Object)

Asynchronously submits the pending changes to the data service collected by the DataServiceContext since the last time changes were saved.

System_CAPS_pubmethod CancelRequest(IAsyncResult)

Attempts to cancel the operation that is associated with the supplied IAsyncResult object.

System_CAPS_pubmethod CreateQuery<T>(String)

Creates a data service query for data of a specified generic type.

System_CAPS_pubmethod DeleteLink(Object, String, Object)

Changes the state of the link to deleted in the list of links being tracked by the DataServiceContext.

System_CAPS_pubmethod DeleteObject(Object)

Changes the state of the specified object to be deleted in the DataServiceContext.

System_CAPS_pubmethod Detach(Object)

Removes the entity from the list of entities that the DataServiceContext is tracking.

System_CAPS_pubmethod DetachLink(Object, String, Object)

Removes the specified link from the list of links being tracked by the DataServiceContext.

System_CAPS_pubmethod EndExecute<TElement>(IAsyncResult)

Called to complete the BeginExecute<TElement>.

System_CAPS_pubmethod EndExecuteBatch(IAsyncResult)

Called to complete the BeginExecuteBatch.

System_CAPS_pubmethod EndGetReadStream(IAsyncResult)

Called to complete the asynchronous operation of retrieving a binary property as a stream.

System_CAPS_pubmethod EndLoadProperty(IAsyncResult)

Called to complete the BeginLoadProperty operation.

System_CAPS_pubmethod EndSaveChanges(IAsyncResult)

Called to complete the BeginSaveChanges operation.

System_CAPS_pubmethod Equals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethod Execute<T>(DataServiceQueryContinuation<T>)

Sends a request to the data service to retrieve the next page of data in a paged query result.

System_CAPS_pubmethod Execute<TElement>(Uri)

Sends a request to the data service to execute a specific URI.

System_CAPS_pubmethod ExecuteBatch(DataServiceRequest[])

Submits a group of queries as a batch to the data service.

System_CAPS_protmethod Finalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethod GetEntityDescriptor(Object)

Gets the EntityDescriptor for the supplied entity object.

System_CAPS_pubmethod GetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethod GetLinkDescriptor(Object, String, Object)

Gets the LinkDescriptor for a specific link that defines the relationship between two entities.

System_CAPS_pubmethod GetMetadataUri()

Gets a URI of the location of .edmx metadata.

System_CAPS_pubmethod GetReadStream(Object)

Gets binary property data for the specified entity as a data stream.

System_CAPS_pubmethod GetReadStream(Object, DataServiceRequestArgs)

Gets binary property data for the specified entity as a data stream along with the specified message headers.

System_CAPS_pubmethod GetReadStream(Object, String)

Gets binary property data for the specified entity as a data stream, with the specified Accept message header.

System_CAPS_pubmethod GetReadStreamUri(Object)

Gets the URI that is used to return binary property data as a data stream.

System_CAPS_pubmethod GetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethod LoadProperty(Object, String)

Loads deferred content for a specified property from the data service.

System_CAPS_pubmethod LoadProperty(Object, String, DataServiceQueryContinuation)

Loads the next page of related entities from the data service by using the supplied query continuation object.

System_CAPS_pubmethod LoadProperty(Object, String, Uri)

Loads a page of related entities by using the supplied next link URI.

System_CAPS_pubmethod 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.

System_CAPS_protmethod MemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethod SaveChanges()

Saves the changes that the DataServiceContext is tracking to storage.

System_CAPS_pubmethod SaveChanges(SaveChangesOptions)

Saves the changes that the DataServiceContext is tracking to storage.

System_CAPS_pubmethod SetLink(Object, String, Object)

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.

System_CAPS_pubmethod SetSaveStream(Object, Stream, Boolean, DataServiceRequestArgs)

Sets a new data stream as the binary property of an entity, with the specified settings in the request message.

System_CAPS_pubmethod SetSaveStream(Object, Stream, Boolean, String, String)

Sets a new data stream as the binary property of an entity. The specified Content-Type and Slug headers are included in the request message.

System_CAPS_pubmethod ToString()

Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_pubmethod TryGetEntity<TEntity>(Uri, TEntity)

Test retrieval of an entity being tracked by the DataServiceContext by reference to the URI of the entity.

System_CAPS_pubmethod TryGetUri(Object, Uri)

Retrieves the canonical URI associated with the specified entity, if available.

System_CAPS_pubmethod UpdateObject(Object)

Changes the state of the specified object in the DataServiceContext to Modified.

Name Description
System_CAPS_pubevent ReadingEntity

Occurs after entity data has been completely read into the entity object.

System_CAPS_pubevent SendingRequest

Occurs when a new HttpWebRequest has been created.

System_CAPS_pubevent WritingEntity

Occurs after an entity has been fully serialized into XML in a request message.

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.

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 .

' 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
.NET Framework
Available since 3.5
Silverlight
Available since 2.0

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

Return to top