Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

22 ms

Page Size

25

Current Page

458 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 458 Results Showing 11426 - 11450 of 24441

ID Name Category Price Stock Rating Reviews SKU
11985 Bulk Product b5429579 Home & Garden $696.73 408 3.8 90 BULK-e5de19f8
11986 Bulk Product 79a9dc86 Sports & Outdoors $701.62 59 3.6 9 BULK-121d0194
11987 Bulk Product adada67d Toys & Games $640.72 347 3.4 64 BULK-aa6ffc7f
11988 Bulk Product 73695822 Sports & Outdoors $293.06 484 4.4 53 BULK-b17b7cc7
11989 Bulk Product 9311aa77 Toys & Games $468.09 442 3.0 72 BULK-60d51cc4
11990 Bulk Product 63a07b36 Electronics $639.81 154 0.3 82 BULK-20db7554
11991 Bulk Product 267f06b4 Sports & Outdoors $477.07 272 0.7 62 BULK-55405765
11992 Bulk Product bfbfffe8 Clothing $277.27 179 1.4 52 BULK-4e66c8da
11993 Bulk Product 2617f3d6 Home & Garden $828.99 412 1.6 97 BULK-a735ccd8
11994 Bulk Product 8169495b Clothing $451.43 284 1.0 20 BULK-aecb8fba
11995 Bulk Product 9257ebcb Books $147.42 78 3.6 98 BULK-750d54e3
11996 Bulk Product 85b80758 Books $408.42 59 4.7 33 BULK-8b658097
11997 Bulk Product d9056812 Home & Garden $924.26 133 1.7 13 BULK-61ac13d1
11998 Bulk Product 81d9e7b3 Home & Garden $645.95 200 3.9 57 BULK-60d02099
11999 Bulk Product 99e4d6e5 Clothing $217.03 122 0.6 39 BULK-33606f67
12000 Bulk Product dbe927b7 Sports & Outdoors $523.18 463 4.3 27 BULK-3bab24b9
12001 Bulk Product 32e44b5a Home & Garden $852.93 123 1.2 42 BULK-943b88bc
12002 Bulk Product b9d4dd77 Clothing $662.94 440 3.4 65 BULK-fadbedf9
12003 Bulk Product 7f2e2a7e Sports & Outdoors $225.64 89 4.3 83 BULK-149416af
12004 Bulk Product f594f007 Clothing $415.42 180 4.3 0 BULK-ae56a8e0
12005 Bulk Product ea97281e Electronics $623.73 335 4.2 14 BULK-6bcf2823
12006 Bulk Product f6704397 Clothing $650.19 455 2.0 76 BULK-70a2a66f
12007 Bulk Product 3c80ffdd Home & Garden $731.74 161 2.5 9 BULK-50367cdd
12008 Bulk Product 1c8aeef4 Home & Garden $550.44 123 4.3 73 BULK-c9a4ece9
12009 Bulk Product 98fe8864 Home & Garden $870.57 103 3.1 46 BULK-c31aee40
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