oData使用过滤器分页

时间:2017-03-12 11:07:24

标签: vb.net odata

我可以使用查询中的Where子句查询odata并获取我需要的前50个结果。我试图弄清楚如何在使用WCF服务客户端进行分页时添加where子句。有一百万个C#示例,但我无法弄清楚vb的语法。到目前为止,我有......

Public Sub CycleData()

    ' Create the DataServiceContext using the service URI.
    Dim ExigoURI As Uri = New Uri("http://api.Exigo.com/4.0/abc/model", UriKind.Absolute)

    ' Create a new instance of the typed DataServiceContext.
    Dim context As ExigoContext = New ExigoContext(ExigoURI)

    context.Credentials = New NetworkCredential("xxx", "yyy")
    Dim token As DataServiceQueryContinuation(Of PeriodRankScore) = Nothing
    Dim pageCount As Integer



    Try
        ' Execute the query for all customers and get the response object.
        Dim response As QueryOperationResponse(Of PeriodRankScore) =
        CType(context.PeriodRankScores(Query).Execute(), QueryOperationResponse(Of PeriodRankScore))

        ' With a paged response from the service, use a do...while loop 
        ' to enumerate the results before getting the next link.
        Do
            ' Write the page number.
            Console.WriteLine("Page {0}:", pageCount + 1)

            ' If nextLink is not null, then there is a new page to load.
            If token IsNot Nothing Then
                ' Load the new page from the next link URI.
                response = CType(context.Execute(Of PeriodRankScore)(token),
                QueryOperationResponse(Of PeriodRankScore))
            End If

            '' Enumerate the customers in the response.
            For Each customer As PeriodRankScore In response
                Console.WriteLine("CustomerID: PeriodID: RankID: {0} {1} {2}", customer.CustomerID, customer.PeriodID, customer.PaidRankID)
            Next

            ' Get the next link, and continue while there is a next link.
            token = response.GetContinuation()
        Loop While token IsNot Nothing
    Catch ex As DataServiceQueryException
        Throw New ApplicationException(
        "An error occurred during query execution.", ex)
    End Try

End Sub

我想添加这样的东西......

CType(context.PeriodRankScores.Where(Function(a) a.PeriodID = 12).Execute(), QueryOperationResponse(Of PeriodRankScore))

1 个答案:

答案 0 :(得分:0)

想知道是否有人好奇!

  Dim query As DataServiceQuery(Of PeriodRankScore) = From PaidRanking In context.PeriodRankScores
                                                        Where PaidRanking.PeriodID = 74 And PaidRanking.PeriodTypeID = 12 And PaidRanking.Score = 100
                                                        Select PaidRanking
                                                        Order By PaidRanking.CustomerID Ascending

    Try
        ' Execute the query for all customers and get the response object.
        Dim response As QueryOperationResponse(Of PeriodRankScore) =
        CType(query.Execute(), QueryOperationResponse(Of PeriodRankScore))