Page large result sets with LINQ

 

In Microsoft Dynamics CRM Online 2016 Update and Microsoft Dynamics CRM 2016 (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:



int pageSize = 5;

var accountsByPage = (from a in svcContext.AccountSet
                      select new Account
                      {
                       Name = a.Name,
                      });
System.Console.WriteLine("Skip 10 accounts, then Take 5 accounts");
System.Console.WriteLine("======================================");
foreach (var a in accountsByPage.Skip(2 * pageSize).Take(pageSize))
{
 System.Console.WriteLine(a.Name);
}

Microsoft Dynamics CRM 2016 and CRM Online

© 2016 Microsoft. All rights reserved. Copyright

Community Additions

ADD
Show: