DataService 的批量查詢

摘要:DataService 的批量查詢

為了節省與Server端的交換頻率,我們盡可能用較少的交互來的到想要的資料.所以調用DataService也是如此.以下通過一次交互來查詢兩個表資料.

 


 Dim svc = DataServiceFactory.CreateInstance()

        Dim resps = svc.ExecuteBatch(New DataServiceRequest(Of User)(New Uri(String.Format("tblUser?$filter=UserID eq '{0}'", "Magic"), UriKind.Relative)), _
                                    New DataServiceRequest(Of  Role)(New Uri("tblRole", UriKind.Relative)))
  
        For Each resp As QueryOperationResponse In resps
            If resp.Query.ElementType = GetType(User) Then
                For Each u In resp.OfType(Of User)()
                   'process u
                Next
            End If

            If resp.Query.ElementType = GetType(Role) Then

                For Each r In resp.OfType(Of Role)()
                   ' process r
                Next
            End If
        Next

 


人生到處知何似
應似飛鴻踏雪泥