本文整理汇总了VB.NET中System.Data.Services.Client.DataServiceContext.ExecuteBatch方法的典型用法代码示例。如果您正苦于以下问题:VB.NET DataServiceContext.ExecuteBatch方法的具体用法?VB.NET DataServiceContext.ExecuteBatch怎么用?VB.NET DataServiceContext.ExecuteBatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.Services.Client.DataServiceContext
的用法示例。
在下文中一共展示了DataServiceContext.ExecuteBatch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: NorthwindEntities
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