Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

34 ms

Page Size

25

Current Page

862 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 862 Results Showing 21526 - 21550 of 24441

ID Name Category Price Stock Rating Reviews SKU
22085 Bulk Product 0c226490 Clothing $214.92 61 3.1 32 BULK-1f153c8d
22086 Bulk Product 06bc8963 Electronics $286.56 71 2.7 38 BULK-adb208d0
22087 Bulk Product 21a54092 Clothing $239.00 331 4.1 30 BULK-a1992db2
22088 Bulk Product f8da858a Clothing $182.17 404 4.1 15 BULK-9429a0c9
22089 Bulk Product e37f7f57 Books $1,002.18 286 0.7 2 BULK-3ff0a52f
22090 Bulk Product 8245d1ab Home & Garden $730.36 15 4.7 49 BULK-3bf88206
22091 Bulk Product 35f8aab8 Home & Garden $283.02 129 4.3 62 BULK-6eaccb23
22092 Bulk Product 5e57e4db Sports & Outdoors $867.61 338 3.0 4 BULK-acd4c7c8
22093 Bulk Product 338d5ba6 Electronics $510.04 92 0.6 99 BULK-7bd3cf8c
22094 Bulk Product f4d6bfd7 Books $147.64 345 4.3 15 BULK-ab51683a
22095 Bulk Product f6ca3ef5 Toys & Games $81.53 284 0.5 52 BULK-a13ffe26
22096 Bulk Product c2b5e31b Home & Garden $399.17 488 4.9 83 BULK-7fcf3c50
22097 Bulk Product 1b0a4648 Toys & Games $129.74 146 2.2 40 BULK-83dd3eb6
22098 Bulk Product 6119755a Electronics $218.74 226 2.8 99 BULK-b10bf49b
22099 Bulk Product ecda17a3 Home & Garden $1,005.98 197 4.0 45 BULK-fafe0401
22100 Bulk Product a4260607 Sports & Outdoors $915.77 7 3.4 15 BULK-1591afdc
22101 Bulk Product 26e9c53e Books $258.17 433 0.2 9 BULK-32e09fc3
22102 Bulk Product f575d9b9 Toys & Games $791.37 93 2.9 12 BULK-262d1d69
22103 Bulk Product a5bc50cd Clothing $664.62 72 2.5 91 BULK-a4968f72
22104 Bulk Product 3e240db3 Electronics $545.01 61 4.4 16 BULK-157ab908
22105 Bulk Product 21033939 Clothing $458.18 28 4.8 43 BULK-0f0196ee
22106 Bulk Product 55f038fd Home & Garden $165.75 130 3.6 81 BULK-9aa2230e
22107 Bulk Product b0b434a9 Toys & Games $782.44 453 2.7 34 BULK-e4285e6f
22108 Bulk Product d674d2fc Sports & Outdoors $160.69 240 3.5 41 BULK-d9a7af8d
22109 Bulk Product 1a003907 Clothing $739.35 402 1.2 50 BULK-80b0b5c7
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