Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

898 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 898 Results Showing 22426 - 22450 of 24441

ID Name Category Price Stock Rating Reviews SKU
22985 Bulk Product 3f5f252b Clothing $301.28 458 3.3 49 BULK-db257bca
22986 Bulk Product a1105286 Sports & Outdoors $976.36 431 2.7 39 BULK-7a096e77
22987 Bulk Product f067de14 Toys & Games $302.43 449 1.6 13 BULK-4300815b
22988 Bulk Product 59bb64ab Books $787.95 245 2.3 86 BULK-4f9905a8
22989 Bulk Product 7b0fac35 Sports & Outdoors $306.69 476 1.7 92 BULK-fb98ebd2
22990 Bulk Product 32c29591 Sports & Outdoors $170.07 67 4.2 38 BULK-bf4a990a
22991 Bulk Product 4817553f Sports & Outdoors $988.52 27 0.9 30 BULK-4fe62952
22992 Bulk Product 541a4de9 Sports & Outdoors $586.76 421 1.5 62 BULK-b1d6ad30
22993 Bulk Product 4561ec12 Toys & Games $730.89 32 3.1 45 BULK-69e56479
22994 Bulk Product 6e67420b Clothing $416.17 227 2.1 22 BULK-4bbcab39
22995 Bulk Product 1d16f9b9 Books $331.97 279 4.3 98 BULK-933747bd
22996 Bulk Product 13a0e770 Electronics $623.30 131 3.8 92 BULK-c8eb97e8
22997 Bulk Product 1b901e34 Home & Garden $145.41 227 4.1 96 BULK-e3134176
22998 Bulk Product ada7c034 Home & Garden $469.21 2 4.2 7 BULK-b07ffd44
22999 Bulk Product cd894bfa Toys & Games $713.01 251 1.0 76 BULK-c2fca3c2
23000 Bulk Product 5b72005c Home & Garden $696.61 240 3.6 67 BULK-e0ca6aa3
23001 Bulk Product ed1060d7 Home & Garden $985.43 240 0.1 9 BULK-3507af0f
23002 Bulk Product fe2bc856 Electronics $798.77 224 0.2 35 BULK-3cd38a4b
23003 Bulk Product cb2d29cd Clothing $716.18 54 4.7 32 BULK-7098d3e7
23004 Bulk Product 372e68f2 Toys & Games $10.85 290 1.7 66 BULK-0af4464a
23005 Bulk Product 5060c6b7 Toys & Games $105.77 348 2.6 86 BULK-3e1522f1
23006 Bulk Product 1c62c2d1 Books $854.39 482 2.3 52 BULK-1da543d9
23007 Bulk Product 05fb9ec7 Home & Garden $55.60 215 3.2 53 BULK-95d2dd5b
23008 Bulk Product 80e25945 Electronics $702.93 366 4.7 96 BULK-823221b3
23009 Bulk Product d642ae68 Home & Garden $574.22 40 4.9 23 BULK-6ba6532b
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