DataServiceContext 類別

定義

DataServiceContext 代表資料服務的執行階段內容。The DataServiceContext represents the runtime context of the data service.

public ref class DataServiceContext
public class DataServiceContext
type DataServiceContext = class
Public Class DataServiceContext
繼承
DataServiceContext

範例

下列範例示範如何使用「加入服務參考」工具所產生的 DataServiceContext,以隱含方式對 Northwind 資料服務執行查詢,傳回所有客戶。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. 內容會自動判斷所要求之 Customers 實體集的 URI。The URI of the requested Customers entity set is determined automatically by the context. 發生列舉時會隱含執行查詢。The query is executed implicitly when the enumeration occurs. 當您完成 WCF Data Services 時,就會建立 Northwind 資料服務。The Northwind data service is created when you complete the WCF Data Services .

// 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);
}
' 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

備註

WCF Data Services 是無狀態的,但 DataServiceContext 不是。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. 這個類別以及 DataServiceQuery 類別 (後者表示對資料服務的特定 HTTP 要求) 是用戶端程式庫中兩個主要類別。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.

建構函式

DataServiceContext(Uri)

使用指定的 DataServiceContext 初始化 serviceRoot 類別的新執行個體。Initializes a new instance of the DataServiceContext class with the specified serviceRoot.

屬性

ApplyingChanges

取得值,該值指出 DataServiceContext 目前是否正在套用追蹤之物件的變更。Gets a value that indicates whether the DataServiceContext is currently applying changes to tracked objects.

BaseUri

取得識別目標資料服務根目錄的絕對 URI。Gets the absolute URI identifying the root of the target data service.

Credentials

取得或設定驗證資訊,此資訊為透過 DataServiceContext 物件所建立之每個查詢所使用。Gets or sets the authentication information that is used by each query created by using the DataServiceContext object.

DataNamespace

取得或設定 Atom 承載之資料項目 (而非中繼資料項目) 的 XML 命名空間 (Namespace)。Gets or sets the XML namespace for data items, not metadata items, of an Atom payload.

Entities

取得 DataServiceContext 目前正在追蹤的所有資源之清單。Gets a list of all the resources currently being tracked by the DataServiceContext.

IgnoreMissingProperties

取得或設定從型別讀取的屬性是否必須對應至用戶端型別上的屬性。Gets or sets whether the properties read from the type must be mapped to properties on the client-side type.

IgnoreResourceNotFoundException

取得或設定是否在資料服務傳回 404 錯誤 (找不到資源) 時引發例外狀況。Gets or sets whether an exception is raised when a 404 error (resource not found) is returned by the data service.

Links

取得 DataServiceContext 物件目前正在追蹤的所有關聯或連結之集合。Gets the collection of all associations or links currently being tracked by the DataServiceContext object.

MergeOption

取得或設定從資料服務接收實體 (Entity) 的同步處理選項。Gets or sets the synchronization option for receiving entities from a data service.

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

取得或設定 SaveChangesOptions 方法所使用的 SaveChanges() 值。Gets or sets the SaveChangesOptions values that are used by the SaveChanges() method.

Timeout

取得或設定逾時選項,用於對資料服務的基礎 HTTP 要求。Gets or sets the time-out option that is used for the underlying HTTP request to the data service.

TypeScheme

取得或設定用來表示服務使用哪種型別配置的 URI。Gets or sets the URI used to indicate what type scheme is used by the service.

UsePostTunneling

取得或設定布林值,這個值表示否要使用 Post 通道。Gets or sets a Boolean value that indicates whether to use post tunneling.

方法

AddLink(Object, String, Object)

將指定的連結加入 DataServiceContext 正在追蹤的物件集。Adds the specified link to the set of objects the DataServiceContext is tracking.

AddObject(String, Object)

將指定的物件加入 DataServiceContext 正在追蹤的物件集。Adds the specified object to the set of objects that the DataServiceContext is tracking.

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.

AttachLink(Object, String, Object)

通知 DataServiceContext 開始追蹤指定的連結,此連結定義實體物件之間的關聯性。Notifies the DataServiceContext to start tracking the specified link that defines a relationship between entity objects.

AttachTo(String, Object)

通知 DataServiceContext,開始追蹤指定的資源,並提供指定的資源集內資源的位置。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)

通知 DataServiceContext 開始追蹤指定的資源並提供資源在指定之資源集內的位置。Notifies the DataServiceContext to start tracking the specified resource and supplies the location of the resource in the specified resource set.

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)

以非同步方式傳送要求,讓這個呼叫不會在等候來自服務的結果時封鎖處理。Asynchronously sends the request so that this call does not block processing while waiting for the results from the service.

BeginExecuteBatch(AsyncCallback, Object, DataServiceRequest[])

以非同步方式和批次方式將一組查詢送出至資料服務。Asynchronously submits a group of queries as a batch to the data service.

BeginGetReadStream(Object, DataServiceRequestArgs, AsyncCallback, Object)

以非同步方式來取得做為資料流之指定實體的二進位屬性資料,以及指定的訊息標題。Asynchronously gets binary property data for the specified entity as a data stream along with 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)

透過使用提供的下一個連結 URI,以非同步方式從資料服務載入一頁相關實體。Asynchronously loads a page of related entities from the data service by using the supplied next link URI.

BeginSaveChanges(AsyncCallback, Object)

以非同步方式將自從上一次儲存變更後 DataServiceContext 所收集之暫止的變更送出至資料服務。Asynchronously submits the pending changes to the data service collected by the DataServiceContext since the last time changes were saved.

BeginSaveChanges(SaveChangesOptions, AsyncCallback, Object)

以非同步方式將自從上一次儲存變更後 DataServiceContext 所收集之暫止的變更送出至資料服務。Asynchronously submits the pending changes to the data service collected by the DataServiceContext since the last time changes were saved.

CancelRequest(IAsyncResult)

嘗試取消與所提供之 IAsyncResult 物件相關聯的作業。Attempts to cancel the operation that is associated with the supplied IAsyncResult object.

CreateQuery<T>(String)

為指定之泛型型別的資料建立資料服務查詢。Creates a data service query for data of a specified generic type.

DeleteLink(Object, String, Object)

DataServiceContext 正在追蹤的連結清單中的連結狀態變更成已刪除。Changes the state of the link to deleted in the list of links being tracked by the DataServiceContext.

DeleteObject(Object)

DataServiceContext 中指定之物件的狀態變更成已刪除。Changes the state of the specified object to be deleted in the DataServiceContext.

Detach(Object)

DataServiceContext 正在追蹤的實體清單中移除實體。Removes the entity from the list of entities that the DataServiceContext is tracking.

DetachLink(Object, String, Object)

DataServiceContext 正在追蹤的連結清單中移除指定的連結。Removes the specified link from the list of links being tracked by the DataServiceContext.

EndExecute<TElement>(IAsyncResult)

呼叫以完成 BeginExecute<TElement>(Uri, AsyncCallback, Object)Called to complete the BeginExecute<TElement>(Uri, AsyncCallback, Object).

EndExecuteBatch(IAsyncResult)

呼叫以完成 BeginExecuteBatch(AsyncCallback, Object, DataServiceRequest[])Called to complete the BeginExecuteBatch(AsyncCallback, Object, DataServiceRequest[]).

EndGetReadStream(IAsyncResult)

呼叫以完成擷取做為資料流之二進位屬性的非同步作業。Called to complete the asynchronous operation of retrieving a binary property as a stream.

EndLoadProperty(IAsyncResult)

呼叫以完成 BeginLoadProperty(Object, String, AsyncCallback, Object) 作業。Called to complete the BeginLoadProperty(Object, String, AsyncCallback, Object) operation.

EndSaveChanges(IAsyncResult)

呼叫以完成 BeginSaveChanges(AsyncCallback, Object) 作業。Called to complete the BeginSaveChanges(AsyncCallback, Object) operation.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
Execute<T>(DataServiceQueryContinuation<T>)

傳送要求給資料服務,在分頁式查詢結果中擷取下一頁資料。Sends a request to the data service to retrieve the next page of data in a paged query result.

Execute<TElement>(Uri)

將要求傳送到資料服務來執行特定的 URI。Sends a request to the data service to execute a specific URI.

ExecuteBatch(DataServiceRequest[])

以批次方式將一組查詢送出至資料服務。Submits a group of queries as a batch to the data service.

GetEntityDescriptor(Object)

取得所提供之實體物件的 EntityDescriptorGets the EntityDescriptor for the supplied entity object.

GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetLinkDescriptor(Object, String, Object)

針對定義兩個實體之間關聯性的特定連結取得 LinkDescriptorGets the LinkDescriptor for a specific link that defines the relationship between two entities.

GetMetadataUri()

取得 .edmx 中繼資料位置的統一資源識別元 (URI)。Gets a URI of the location of .edmx metadata.

GetReadStream(Object)

取得指定之實體的二進位屬性資料做為資料流。Gets binary property data for the specified entity as a data stream.

GetReadStream(Object, DataServiceRequestArgs)

取得做為資料流之指定實體的二進位屬性資料,以及指定的訊息標題。Gets binary property data for the specified entity as a data stream along with the specified message headers.

GetReadStream(Object, String)

取得做為資料流之指定實體的二進位屬性資料,以及指定的 Accept 訊息標題。Gets binary property data for the specified entity as a data stream, with the specified Accept message header.

GetReadStreamUri(Object)

取得用來傳回做為資料流之二進位屬性資料的 URI。Gets the URI that is used to return binary property data as a data stream.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
LoadProperty(Object, String)

從資料服務載入指定之屬性的延遲內容。Loads deferred content for a specified property from the data service.

LoadProperty(Object, String, DataServiceQueryContinuation)

透過使用提供的查詢接續物件,從資料服務載入下一頁相關實體。Loads the next page of related entities from the data service by using the supplied query continuation object.

LoadProperty(Object, String, Uri)

透過使用提供的下一個連結 URI,載入一頁相關實體。Loads a page of related entities by using the supplied next link URI.

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.

MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
SaveChanges()

DataServiceContext 正在追蹤的變更儲存至儲存區。Saves the changes that the DataServiceContext is tracking to storage.

SaveChanges(SaveChangesOptions)

DataServiceContext 正在追蹤的變更儲存至儲存區。Saves the changes that the DataServiceContext is tracking to storage.

SetLink(Object, String, Object)

通知 DataServiceContext,來源和指定的目標物件之間存在新連結,以及由 sourceProperty 參數所指定的屬性表示該連結。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 new data stream as the binary property of an entity, with the specified settings in the request message.

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

將新資料流設定為實體的二進位屬性。Sets a new data stream as the binary property of an entity. 指定的內容類型和 Slug 標題會包含在要求訊息中。The specified Content-Type and Slug headers are included in the request message.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)
TryGetEntity<TEntity>(Uri, TEntity)

透過實體 URI 的參考進行測試擷取 DataServiceContext 正在追蹤的實體。Test retrieval of an entity being tracked by the DataServiceContext by reference to the URI of the entity.

TryGetUri(Object, Uri)

擷取與指定之實體相關聯的標準 URI (若有的話)。Retrieves the canonical URI associated with the specified entity, if available.

UpdateObject(Object)

DataServiceContext 中指定之物件的狀態變更成 ModifiedChanges the state of the specified object in the DataServiceContext to Modified.

事件

ReadingEntity

當實體資料已完全讀入實體物件之後發生。Occurs after entity data has been completely read into the entity object.

SendingRequest

已建立新的 HttpWebRequest 時發生。Occurs when a new HttpWebRequest has been created.

WritingEntity

實體已完全序列化為要求訊息中的 XML 之後發生。Occurs after an entity has been fully serialized into XML in a request message.

適用於