Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

10 ms

Page Size

25

Current Page

361 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 361 Results Showing 9001 - 9025 of 24441

ID Name Category Price Stock Rating Reviews SKU
9560 Bulk Product 264fc20b Electronics $956.52 468 0.2 67 BULK-7784fa6a
9561 Bulk Product e7a1d5a9 Sports & Outdoors $298.33 182 1.7 60 BULK-89c69e89
9562 Bulk Product 2293d415 Sports & Outdoors $429.46 302 0.8 34 BULK-76fc063e
9563 Bulk Product 3fd0f6b9 Toys & Games $194.78 173 0.7 0 BULK-f6dd44ff
9564 Bulk Product 8d5b054d Sports & Outdoors $996.75 142 0.5 50 BULK-b2a8e997
9565 Bulk Product 1cfd4fb0 Clothing $793.69 245 1.3 27 BULK-a752b277
9566 Bulk Product 95e50429 Electronics $108.29 124 4.8 55 BULK-6d507091
9567 Bulk Product f7f3e46b Sports & Outdoors $485.99 452 4.3 55 BULK-8bec2a4c
9568 Bulk Product fbea504f Electronics $898.84 236 4.4 40 BULK-3bf182cd
9569 Bulk Product c23f6488 Books $68.69 426 0.3 94 BULK-a074caad
9570 Bulk Product 02ee28d9 Books $869.44 140 3.9 78 BULK-d4212a2f
9571 Bulk Product dc8a0840 Electronics $104.52 202 0.8 54 BULK-6c9b8913
9572 Bulk Product d6f09c6a Home & Garden $436.68 73 3.3 84 BULK-641a0dd4
9573 Bulk Product 447640b3 Home & Garden $30.63 38 2.6 36 BULK-46d9783f
9574 Bulk Product 1ed88ed4 Sports & Outdoors $859.66 130 2.4 30 BULK-a268fb25
9575 Bulk Product 712fd685 Toys & Games $533.97 197 0.4 33 BULK-e2a6e7da
9576 Bulk Product ef1ab4f7 Toys & Games $251.01 2 3.6 19 BULK-af94192a
9577 Bulk Product 211e2aa1 Home & Garden $556.52 178 3.3 60 BULK-3351b73f
9578 Bulk Product 34626658 Sports & Outdoors $218.93 71 4.1 86 BULK-aefae7dd
9579 Bulk Product a1b128d1 Home & Garden $822.11 46 2.3 47 BULK-1948e0c5
9580 Bulk Product a9d62ed6 Sports & Outdoors $293.85 115 4.4 67 BULK-39200693
9581 Bulk Product 60827e35 Books $26.99 401 4.4 49 BULK-c2da3779
9582 Bulk Product d34c8640 Electronics $562.65 302 4.8 12 BULK-ab31a577
9583 Bulk Product 4fe873e1 Sports & Outdoors $310.33 119 3.3 29 BULK-c6223001
9584 Bulk Product b6f28529 Home & Garden $303.96 421 1.1 80 BULK-336f5ba5
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