Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

42 ms

Page Size

25

Current Page

837 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 837 Results Showing 20901 - 20925 of 24441

ID Name Category Price Stock Rating Reviews SKU
21460 Bulk Product 08e4b349 Sports & Outdoors $583.06 466 3.8 14 BULK-68114b7c
21461 Bulk Product 48b25e6e Home & Garden $222.40 29 2.2 35 BULK-4411c86a
21462 Bulk Product 465e1ec1 Home & Garden $690.62 441 2.0 61 BULK-e2ea76df
21463 Bulk Product 7bb380d3 Toys & Games $951.27 467 2.0 21 BULK-6dd86043
21464 Bulk Product 4d8af1a7 Electronics $663.90 114 0.6 75 BULK-d985f93d
21465 Bulk Product d9b73b7f Sports & Outdoors $112.50 336 2.9 22 BULK-3d3ab18c
21466 Bulk Product 814d1e62 Electronics $832.25 364 4.7 92 BULK-677e7b51
21467 Bulk Product 051d38d7 Toys & Games $782.56 276 2.6 16 BULK-2154914e
21468 Bulk Product 72bbe1e0 Clothing $929.84 453 2.0 99 BULK-55f8cd41
21469 Bulk Product 967f44bd Electronics $738.91 106 1.2 12 BULK-8b319cc1
21470 Bulk Product 3a7b65d0 Clothing $51.12 41 4.4 53 BULK-ab6d6683
21471 Bulk Product ccdb74fa Toys & Games $121.63 21 3.7 4 BULK-a8115bf2
21472 Bulk Product 83dffbc7 Home & Garden $638.75 436 1.4 73 BULK-0e71b7bb
21473 Bulk Product 64163233 Sports & Outdoors $77.54 25 3.8 45 BULK-d35f9658
21474 Bulk Product aa786715 Books $539.79 259 2.5 44 BULK-994d375c
21475 Bulk Product e010bcc2 Home & Garden $58.72 369 3.8 0 BULK-2544ff70
21476 Bulk Product 71dd9104 Home & Garden $79.08 115 0.1 83 BULK-fe26f395
21477 Bulk Product da98dc39 Books $151.08 267 4.0 93 BULK-fea05fa5
21478 Bulk Product 22b4fe9c Home & Garden $908.10 158 3.3 82 BULK-26c45e87
21479 Bulk Product d39bd02b Toys & Games $118.35 100 1.7 22 BULK-54a9188b
21480 Bulk Product 606863bb Toys & Games $189.98 73 3.4 89 BULK-a213f456
21481 Bulk Product c7418379 Electronics $368.84 451 4.4 22 BULK-2952f4ed
21482 Bulk Product 2e0071b5 Toys & Games $768.84 151 4.3 17 BULK-68396518
21483 Bulk Product fcccb80e Clothing $979.27 67 1.6 36 BULK-983684c5
21484 Bulk Product 0a219e96 Sports & Outdoors $400.80 128 2.1 95 BULK-c9820fe3
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