Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

94 ms

Page Size

25

Current Page

723 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 723 Results Showing 18051 - 18075 of 24441

ID Name Category Price Stock Rating Reviews SKU
18610 Bulk Product d6b003cf Toys & Games $289.44 28 0.9 89 BULK-d8a6a726
18611 Bulk Product 533f954b Books $197.74 403 1.4 9 BULK-511d33c3
18612 Bulk Product b4989385 Toys & Games $440.82 278 4.2 27 BULK-1ce37de1
18613 Bulk Product 861d5087 Clothing $537.27 446 3.4 17 BULK-8cbb5c70
18614 Bulk Product 7e47bf21 Toys & Games $903.59 317 2.3 59 BULK-e8cec8b8
18615 Bulk Product cd285c51 Electronics $105.80 359 1.6 95 BULK-68d776b8
18616 Bulk Product 0eea56a6 Home & Garden $918.65 188 3.2 79 BULK-45577c07
18617 Bulk Product eefd9e39 Electronics $851.38 245 3.0 64 BULK-ffd89922
18618 Bulk Product 13d204c2 Clothing $810.66 189 0.0 63 BULK-b709a436
18619 Bulk Product d10c013d Books $380.14 394 2.2 76 BULK-26ea63dc
18620 Bulk Product ae2c6d7d Clothing $46.94 16 0.1 79 BULK-5d41b18f
18621 Bulk Product 3dcbf994 Clothing $791.55 371 2.7 72 BULK-1350cbaf
18622 Bulk Product b2394225 Clothing $665.85 17 3.0 24 BULK-5425486c
18623 Bulk Product bf0bc0d1 Clothing $413.83 14 2.7 57 BULK-46008a40
18624 Bulk Product 7676a767 Toys & Games $683.50 244 3.1 49 BULK-adca9d39
18625 Bulk Product 5dbab35d Sports & Outdoors $732.93 399 2.9 20 BULK-23069eee
18626 Bulk Product 2b99d947 Sports & Outdoors $360.59 87 4.1 34 BULK-2f484f47
18627 Bulk Product 0c0943d4 Toys & Games $797.57 45 3.1 15 BULK-07494ae4
18628 Bulk Product 596350e3 Books $23.88 385 3.8 13 BULK-bd6d34ee
18629 Bulk Product 18e7ec6c Electronics $886.25 285 1.2 96 BULK-1da9095b
18630 Bulk Product fcf188c7 Home & Garden $114.02 454 2.2 51 BULK-14a908ed
18631 Bulk Product 2fdc75b5 Books $180.90 369 2.7 48 BULK-3b0c90b8
18632 Bulk Product ca570613 Electronics $187.84 146 2.8 73 BULK-02841c81
18633 Bulk Product 707c49ab Home & Garden $95.54 386 2.2 33 BULK-52194dd7
18634 Bulk Product 554d9d0a Sports & Outdoors $435.13 180 3.4 48 BULK-5838640a
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