Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

235 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 235 Results Showing 5851 - 5875 of 24441

ID Name Category Price Stock Rating Reviews SKU
6410 Bulk Product 79251fbd Home & Garden $231.84 38 3.2 13 BULK-ae98d106
6411 Bulk Product fb3980da Books $852.39 203 4.5 54 BULK-0a9a0939
6412 Bulk Product 1c4b0bf1 Sports & Outdoors $252.37 496 1.5 16 BULK-1751a524
6413 Bulk Product bacb1349 Clothing $656.03 32 4.1 19 BULK-7ec7626b
6414 Bulk Product e7175642 Toys & Games $636.62 456 2.5 46 BULK-4b653b50
6415 Bulk Product e5b47ab1 Books $235.59 439 1.1 69 BULK-698abb7b
6416 Bulk Product bc5bf6ac Books $146.81 443 3.0 9 BULK-8fbfed65
6417 Bulk Product baf0a6b6 Books $718.52 234 3.7 98 BULK-73bc95cb
6418 Bulk Product b4426165 Sports & Outdoors $55.88 11 3.2 13 BULK-523ab4c7
6419 Bulk Product 09e3e370 Electronics $852.34 451 4.7 16 BULK-548fefab
6420 Bulk Product bc6480d7 Clothing $530.02 270 2.2 71 BULK-bf987565
6421 Bulk Product 5452bb56 Home & Garden $291.54 276 3.3 90 BULK-b786d164
6422 Bulk Product 05316b8a Toys & Games $552.76 173 3.6 58 BULK-9a5326c7
6423 Bulk Product 421e857a Home & Garden $422.75 305 4.4 27 BULK-4402ebb8
6424 Bulk Product 7a01b10f Sports & Outdoors $292.77 303 1.3 26 BULK-6bc51b49
6425 Bulk Product 1e2cc839 Home & Garden $778.41 343 0.7 66 BULK-105cb362
6426 Bulk Product eae7a3fb Electronics $443.98 455 0.7 13 BULK-d61e1889
6427 Bulk Product 3cbd8cb6 Electronics $702.17 448 3.3 95 BULK-93b7854a
6428 Bulk Product 20484335 Toys & Games $597.44 50 1.7 65 BULK-5bbac261
6429 Bulk Product cc4b3a2f Electronics $805.36 360 0.1 67 BULK-3b8bfa7e
6430 Bulk Product 085b0933 Electronics $513.50 446 2.5 77 BULK-e5983e69
6431 Bulk Product d8cb70fb Books $162.73 118 4.9 10 BULK-f2796b51
6432 Bulk Product 1726c4c8 Toys & Games $613.87 259 3.8 43 BULK-45f919d3
6433 Bulk Product 7694edf2 Electronics $811.44 447 1.3 34 BULK-3cff327c
6434 Bulk Product 6d14c174 Electronics $409.32 363 2.6 36 BULK-6af3c638
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