쿼리 그룹을 일괄 처리로 데이터 서비스에 동기적으로 전송합니다.
Silverlight용 WCF Data Services 5.0 클라이언트에서 지원되지 않습니다.
네임스페이스: System.Data.Services.Client
어셈블리: Microsoft.Data.Services.Client(Microsoft.Data.Services.Client.dll)
구문
‘선언
Public Function ExecuteBatch ( _
ParamArray queries As DataServiceRequest() _
) As DataServiceResponse
‘사용 방법
Dim instance As DataServiceContext
Dim queries As DataServiceRequest()
Dim returnValue As DataServiceResponse
returnValue = instance.ExecuteBatch(queries)
public DataServiceResponse ExecuteBatch(
params DataServiceRequest[] queries
)
public:
DataServiceResponse^ ExecuteBatch(
... array<DataServiceRequest^>^ queries
)
member ExecuteBatch :
queries:DataServiceRequest[] -> DataServiceResponse
public function ExecuteBatch(
... queries : DataServiceRequest[]
) : DataServiceResponse
매개 변수
- queries
유형: array<System.Data.Services.Client.DataServiceRequest[]
쿼리를 구성하는 array<DataServiceRequest[] 개체의 배열입니다.
반환 값
유형: System.Data.Services.Client.DataServiceResponse
일괄 처리 작업에 대한 응답입니다.
주의
쿼리는 DataServiceRequest<TElement> 인스턴스로 지정됩니다. 전체 일괄 처리 요청의 응답을 나타내는 DataServiceResponse를 반환합니다. 개별 쿼리 응답은 DataServiceResponse 인스턴스를 열거하여 액세스할 수 있는 개별 OperationResponse 개체로 표현됩니다.
이 메서드가 반환되면 일괄 처리 요청에 대한 전체 HTTP 응답을 네트워크 스트림에서 읽었지만 응답이 처리되지 않은 것입니다. 응답의 지정된 엔터티가 열거될 때까지 이 엔터티에 대해 ID 확인 또는 개체 구체화가 수행되지 않습니다.
예
다음 예제에서는 Northwind 데이터 서비스에서 Customers 개체와 Products 개체를 모두 반환하는 쿼리가 포함된 DataServiceRequest<TElement> 개체 배열을 실행하는 ExecuteBatch() 메서드를 호출하는 방법을 보여 줍니다. 반환된 DataServiceResponse의 QueryOperationResponse<T> 개체 컬렉션이 열거되고 각 QueryOperationResponse<T>에 포함되어 있는 개체 컬렉션도 열거됩니다. 이 예제에서는 WCF Data Services?퀵 스타트를 완료하면 생성되는 Northwind 데이터 서비스를 기반으로 서비스 참조 추가 도구에서 생성된 DataServiceContext를 사용합니다.
Dim customerId = "ALFKI"
' Create the DataServiceContext using the service URI.
Dim context = New NorthwindEntities(svcUri)
' Create the separate query URI's, one that returns
' a single customer and another that returns all Products.
Dim customerUri = New Uri(svcUri.AbsoluteUri & _
"/Customers('" & customerId & "')/?$expand=Orders")
Dim productsUri = New Uri(svcUri.AbsoluteUri & _
"/Products")
' Create the query requests.
Dim customerQuery = New DataServiceRequest(Of Customer)(customerUri)
Dim productsQuery = New DataServiceRequest(Of Product)(productsUri)
' Add the query requests to a batch request array.
Dim batchRequests = _
New DataServiceRequest() {customerQuery, productsQuery}
Dim batchResponse As DataServiceResponse
Try
' Execute the query batch and get the response.
batchResponse = context.ExecuteBatch(batchRequests)
If batchResponse.IsBatchResponse Then
' Parse the batchResponse.BatchHeaders.
End If
' Enumerate over the results of the query.
For Each response As QueryOperationResponse In batchResponse
' Handle an error response.
If response.StatusCode > 299 OrElse response.StatusCode < 200 Then
Console.WriteLine("An error occurred.")
Console.WriteLine(response.Error.Message)
Else
' Find the response for the Customers query.
If response.Query.ElementType Is GetType(Customer) Then
For Each customer As Customer In response
Console.WriteLine("Customer: {0}", customer.CompanyName)
For Each order As Order In customer.Orders
Console.WriteLine("Order ID: {0} - Freight: {1}", _
order.OrderID, order.Freight)
Next
Next
' Find the response for the Products query.
ElseIf response.Query.ElementType Is GetType(Product) Then
For Each product As Product In response
Console.WriteLine("Product: {0}", product.ProductName)
Next
End If
End If
Next
' This type of error is raised when the data service returns with
' a response code < 200 or >299 in the top level element.
Catch ex As DataServiceRequestException
' Get the response from the exception.
batchResponse = ex.Response
If (batchResponse.IsBatchResponse) Then
' Parse the batchResponse.BatchHeaders.
End If
For Each response As QueryOperationResponse In batchResponse
If response.Error IsNot Nothing Then
Console.WriteLine("An error occurred.")
Console.WriteLine(response.Error.Message)
End If
Next
End Try
string customerId = "ALFKI";
// Create the DataServiceContext using the service URI.
NorthwindEntities context = new NorthwindEntities(svcUri);
// Create the separate query URI's, one that returns
// a single customer and another that returns all Products.
Uri customerUri = new Uri(svcUri.AbsoluteUri +
"/Customers('" + customerId + "')/?$expand=Orders");
Uri productsUri = new Uri(svcUri.AbsoluteUri +
"/Products");
// Create the query requests.
DataServiceRequest<Customer> customerQuery =
new DataServiceRequest<Customer>(customerUri);
DataServiceRequest<Product> productsQuery =
new DataServiceRequest<Product>(productsUri);
// Add the query requests to a batch request array.
DataServiceRequest[] batchRequests =
new DataServiceRequest[]{customerQuery, productsQuery};
DataServiceResponse batchResponse;
try
{
// Execute the query batch and get the response.
batchResponse = context.ExecuteBatch(batchRequests);
if (batchResponse.IsBatchResponse)
{
// Parse the batchResponse.BatchHeaders.
}
// Enumerate over the results of the query.
foreach (QueryOperationResponse response in batchResponse)
{
// Handle an error response.
if (response.StatusCode > 299 || response.StatusCode < 200)
{
Console.WriteLine("An error occurred.");
Console.WriteLine(response.Error.Message);
}
else
{
// Find the response for the Customers query.
if (response.Query.ElementType == typeof(Customer))
{
foreach (Customer customer in response)
{
Console.WriteLine("Customer: {0}", customer.CompanyName);
foreach (Order order in customer.Orders)
{
Console.WriteLine("Order ID: {0} - Freight: {1}",
order.OrderID, order.Freight);
}
}
}
// Find the response for the Products query.
else if (response.Query.ElementType == typeof(Product))
{
foreach (Product product in response)
{
Console.WriteLine("Product: {0}", product.ProductName);
}
}
}
}
}
// This type of error is raised when the data service returns with
// a response code < 200 or >299 in the top level element.
catch (DataServiceRequestException e)
{
// Get the response from the exception.
batchResponse = e.Response;
if (batchResponse.IsBatchResponse)
{
// Parse the batchResponse.BatchHeaders.
}
foreach (QueryOperationResponse response in batchResponse)
{
if (response.Error != null)
{
Console.WriteLine("An error occurred.");
Console.WriteLine(response.Error.Message);
}
}
}
참고 항목
참조
System.Data.Services.Client 네임스페이스