Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

791 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 791 Results Showing 19751 - 19775 of 24441

ID Name Category Price Stock Rating Reviews SKU
20310 Bulk Product c86873da Toys & Games $748.20 261 2.8 92 BULK-8121d3d4
20311 Bulk Product f08deba2 Clothing $589.64 459 3.4 93 BULK-637d15c4
20312 Bulk Product 83493ff6 Sports & Outdoors $751.10 279 2.9 16 BULK-80fb80af
20313 Bulk Product 73e5bb3d Clothing $732.29 484 2.9 89 BULK-e3af85e3
20314 Bulk Product 1af8bf7a Electronics $951.86 180 3.6 59 BULK-6b12fb0d
20315 Bulk Product bb7363fc Home & Garden $730.19 458 4.0 16 BULK-73057148
20316 Bulk Product 22e24185 Sports & Outdoors $272.62 436 3.6 35 BULK-00192674
20317 Bulk Product a1661fdd Books $163.02 340 0.2 67 BULK-00514268
20318 Bulk Product 414d8516 Electronics $855.85 459 0.4 53 BULK-05d5d5ad
20319 Bulk Product c819bb71 Home & Garden $334.06 429 2.0 92 BULK-663eeb5d
20320 Bulk Product 56eadd24 Home & Garden $577.21 230 2.8 6 BULK-bcc8d751
20321 Bulk Product 5aab8483 Sports & Outdoors $87.11 275 1.7 14 BULK-322a8235
20322 Bulk Product 3b8777d1 Electronics $288.75 127 4.3 12 BULK-b889c8c9
20323 Bulk Product 1cff7cc9 Clothing $436.23 190 0.1 8 BULK-75511343
20324 Bulk Product bcde2394 Books $21.45 207 0.6 8 BULK-d5d1aff0
20325 Bulk Product ba79e18f Toys & Games $545.59 234 4.5 52 BULK-cacf352b
20326 Bulk Product 38af316c Books $340.59 125 1.5 47 BULK-510340b8
20327 Bulk Product ff9501aa Books $510.48 155 2.9 42 BULK-d87bab1e
20328 Bulk Product f65e85ae Home & Garden $335.43 498 3.4 98 BULK-0810b844
20329 Bulk Product 461b93be Clothing $810.96 416 3.1 92 BULK-96ea2110
20330 Bulk Product dc36c51d Home & Garden $294.40 87 3.9 38 BULK-9904c48b
20331 Bulk Product 42e6630c Electronics $227.81 361 4.6 51 BULK-2cc8dd02
20332 Bulk Product f05c8367 Clothing $355.80 235 2.1 71 BULK-84bb9c3f
20333 Bulk Product 0a46c14b Home & Garden $109.11 258 0.6 64 BULK-ebbd9b01
20334 Bulk Product 314e0d64 Electronics $968.71 225 3.3 4 BULK-a81c5192
Implementation Code
// Efficient pagination with Skip and Take
public async Task<PaginatedResult<DemoProduct>> GetPaginatedProductsAsync(int page, int pageSize)
{
    // Get total count (cached if possible)
    var totalCount = await _context.DemoProducts.CountAsync(p => p.IsActive);
    
    // Get page of results
    var items = await _context.DemoProducts
        .Where(p => p.IsActive)
        .OrderBy(p => p.Id) // Important: Must have ORDER BY for consistent paging
        .Skip((page - 1) * pageSize) // OFFSET in SQL
        .Take(pageSize) // FETCH NEXT in SQL
        .AsNoTracking() // No tracking needed for read-only
        .ToListAsync();

    return new PaginatedResult<DemoProduct>
    {
        Items = items,
        TotalCount = totalCount,
        Page = page,
        PageSize = pageSize
    };
}
Pagination Best Practices
  • Always use OrderBy: Skip/Take require stable sorting for consistent results
  • Use AsNoTracking(): Pagination queries are typically read-only
  • Consider caching: Cache total count if dataset changes infrequently
  • Limit max page size: Prevent users from requesting too many records at once
  • Use indexed columns: Ensure ORDER BY columns are indexed for performance