Efficient paging with MembershipUser object and pageddatasource

peter liles 556 Reputation points
2021-09-10T19:09:14.363+00:00

I am trying to implement efficient paging using LINQ like:

Dim numberOfObjectsPerPage As Integer = ddlPageSize.SelectedValue
Dim queryResultPage = MembershipUserODS.GetMembersCompose(sortexpression, usernametofind, roleid, UsernameToMatch, Me.PageIndex, totalRecords)
queryResultPage.Skip(numberOfObjectsPerPage * Me.PageIndex).Take(numberOfObjectsPerPage)

        pagingSource.DataSource = queryResultPage

The queryResultPage variable returns the total row count and not the subset page size value as expected?

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,359 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Lan Huang-MSFT 27,716 Reputation points Microsoft Vendor
    2021-09-15T09:47:12.1+00:00

    Hi @peter liles ,

    Return memberList.Skip(startIndex).Take(maxRows).ToList()

    Regarding Skip(1).Take(5), skip the first data and take 5 data from the second.
    What are the values of startIndex and maxRows?
    Maybe you can imitate the following code:
    132401-1.png


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Lan Huang


  2. peter liles 556 Reputation points
    2021-09-29T13:24:01.06+00:00

    It is set by a function like below.The membershipuserwrapper is a membershipuser class. i have tried various parameters to test results and it does not effect the output.it still returns the full count ?

    Private Shared memberList As List(Of MembershipUserWrapper)

        <DataObjectMethod(DataObjectMethodType.[Select], False)>
        Public Shared Function GetMembers(ByVal returnAllApprovedUsers As Boolean, ByVal returnAllNotApprovedUsers As Boolean, ByVal usernameToFind As String, ByVal sortExpression As String, ByVal RoleID As String, ByVal UsernameToMatch As String, ByVal startIndex As Integer, ByVal maxRows As Integer, ByVal Optional TotalRows As Integer = 0) As List(Of MembershipUserWrapper)
    
            memberList = New List(Of MembershipUserWrapper)()
    

    Return memberList.Skip(maxRows * startIndex ).Take(maxRows).ToList


  3. peter liles 556 Reputation points
    2021-10-11T13:23:56+00:00

    Do i need to use LINQ to obtain a subset of data from my membershipuser constructor or can the data parse be done without the skip and take method.
    by calculating the startrow index and max records returned before adding parameters to constructor?

    0 comments No comments