Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

25

Current Page

821 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 821 Results Showing 20501 - 20525 of 24441

ID Name Category Price Stock Rating Reviews SKU
21060 Bulk Product babcb33b Home & Garden $498.64 336 3.7 41 BULK-d911463f
21061 Bulk Product 49c6298b Sports & Outdoors $819.36 318 1.0 71 BULK-d47dccbc
21062 Bulk Product 20f695e4 Clothing $516.82 338 0.4 42 BULK-2bfda243
21063 Bulk Product 68026e65 Toys & Games $450.52 317 2.6 26 BULK-40e7bbef
21064 Bulk Product 0b2b28ee Toys & Games $638.71 433 5.0 1 BULK-f1f935bb
21065 Bulk Product 64d36384 Electronics $646.79 476 0.2 61 BULK-52efc50f
21066 Bulk Product b2a6e721 Sports & Outdoors $549.90 220 3.6 37 BULK-9ef16614
21067 Bulk Product 440d36aa Home & Garden $467.67 60 3.9 97 BULK-a733c2ac
21068 Bulk Product 6b86dcde Home & Garden $990.93 369 3.4 77 BULK-3614fddc
21069 Bulk Product a26488cc Electronics $730.76 365 3.6 65 BULK-c111e682
21070 Bulk Product 7399a2b0 Sports & Outdoors $612.12 247 3.2 29 BULK-e0ee7c5e
21071 Bulk Product 0feec733 Toys & Games $881.86 420 1.5 92 BULK-fc4e20b9
21072 Bulk Product 5d7e4c5e Books $892.00 352 3.1 3 BULK-efcf58ae
21073 Bulk Product bd4e7719 Toys & Games $744.06 67 4.6 20 BULK-f75673c9
21074 Bulk Product 32ce8041 Electronics $595.35 488 2.0 71 BULK-242884db
21075 Bulk Product 7f1a34f5 Home & Garden $960.13 162 2.8 52 BULK-6dd29a9f
21076 Bulk Product 45c5ac32 Sports & Outdoors $938.74 424 3.0 98 BULK-6e6ca4d0
21077 Bulk Product 27bae157 Books $829.17 274 4.2 7 BULK-b94e3637
21078 Bulk Product 311d6591 Sports & Outdoors $936.48 96 1.6 90 BULK-c90d2b30
21079 Bulk Product 42732af2 Books $90.67 408 0.6 26 BULK-22624efa
21080 Bulk Product f9e63a19 Clothing $646.91 58 3.0 26 BULK-d2bec1db
21081 Bulk Product c0656f1d Toys & Games $275.56 79 4.6 19 BULK-aff8d5da
21082 Bulk Product ae3e01f3 Electronics $813.94 451 1.5 72 BULK-6abf67ad
21083 Bulk Product 03b43e5b Sports & Outdoors $349.91 352 2.2 74 BULK-94ee8466
21084 Bulk Product 1a1ca4ec Electronics $40.18 151 1.8 73 BULK-2d20c0e5
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