本文整理汇总了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
开发者ID:VB.NET开发者,项目名称:System.Data.Services.Client,代码行数:70,代码来源:DataServiceContext.ExecuteBatch
注:本文中的System.Data.Services.Client.DataServiceContext.ExecuteBatch方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论