Page large result sets with LINQ


Updated: November 29, 2016

Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

In Microsoft Dynamics 365 (online & on-premises) you can page the results of a large .NET Language-Integrated Query (LINQ) query by using the Take and Skip operators. The Take operator retrieves a specified number of results and the Skip operator skips over a specified number of results.

The following example shows how to page the results of a LINQ query by using the Take and Skip operators:

' Retrieve records with Skip/Take record paging. Setting a page size
' can help you manage your Skip and Take calls, since Skip must be
' passed a multiple of Take's parameter value.
Dim pageSize As Integer = 5

Dim accountsByPage = ( _
    From a In svcContext.CreateQuery(Of Account)() _
    Select New Account With {.Name = a.Name})
Console.WriteLine("Skip 10 accounts, then Take 5 accounts")
For Each a In accountsByPage.Skip(2 * pageSize).Take(pageSize)
Next a
Console.WriteLine("<End of Listing>")

Microsoft Dynamics 365

© 2016 Microsoft. All rights reserved. Copyright

Community Additions