Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

809 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 809 Results Showing 20201 - 20225 of 24441

ID Name Category Price Stock Rating Reviews SKU
20760 Bulk Product d6fcd481 Home & Garden $565.52 58 2.4 40 BULK-2b0b6808
20761 Bulk Product 57106f00 Books $154.69 194 1.9 64 BULK-be347978
20762 Bulk Product 346328ab Sports & Outdoors $805.74 208 2.6 35 BULK-f13e2bae
20763 Bulk Product b41a4a04 Sports & Outdoors $839.81 48 1.4 65 BULK-33f0073b
20764 Bulk Product 13f06b79 Sports & Outdoors $742.92 196 0.3 15 BULK-37fb4cfc
20765 Bulk Product 9eab913f Electronics $34.21 223 1.1 71 BULK-055b9f06
20766 Bulk Product aa6c21f3 Books $951.17 307 2.3 33 BULK-4d2678a1
20767 Bulk Product ed0e48c8 Toys & Games $215.73 83 3.0 41 BULK-a4837d3d
20768 Bulk Product 2201dea8 Clothing $390.51 346 3.7 12 BULK-272bf07f
20769 Bulk Product 58d443be Home & Garden $251.98 162 4.4 91 BULK-0c4e4d68
20770 Bulk Product 804d46bf Home & Garden $416.11 205 0.3 17 BULK-bbe05012
20771 Bulk Product 0046cf1c Toys & Games $809.68 331 4.3 39 BULK-ab1cbf7e
20772 Bulk Product 71ad87f6 Home & Garden $698.74 37 0.3 65 BULK-85671169
20773 Bulk Product 3bbfe7fb Sports & Outdoors $1,009.92 368 4.0 62 BULK-b8583c30
20774 Bulk Product 2aada98a Books $195.87 295 1.6 63 BULK-024ac26f
20775 Bulk Product c9762524 Electronics $348.27 38 0.6 82 BULK-f3953032
20776 Bulk Product fd13de4d Home & Garden $546.85 207 2.9 45 BULK-094fbe4b
20777 Bulk Product 1f8b5748 Clothing $661.96 416 2.0 37 BULK-d84cdace
20778 Bulk Product ee6b30b6 Electronics $735.73 284 0.1 28 BULK-2403c30d
20779 Bulk Product a8881767 Sports & Outdoors $347.60 382 2.6 60 BULK-8a09be5b
20780 Bulk Product f5b733fe Books $364.85 107 1.0 81 BULK-439e0968
20781 Bulk Product ff0ed40f Clothing $875.58 472 0.8 62 BULK-698ce648
20782 Bulk Product da0f6960 Home & Garden $315.48 12 1.8 44 BULK-143c2bc3
20783 Bulk Product dd8ce975 Electronics $433.37 26 2.4 55 BULK-e7a1fb4f
20784 Bulk Product 60dff460 Clothing $391.76 392 2.8 71 BULK-858079d2
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