Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

80 ms

Page Size

25

Current Page

753 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 753 Results Showing 18801 - 18825 of 24441

ID Name Category Price Stock Rating Reviews SKU
19360 Bulk Product 0614df70 Electronics $75.01 392 2.8 54 BULK-815ec45d
19361 Bulk Product 230cd4ce Toys & Games $286.09 441 1.7 56 BULK-d38e3b9b
19362 Bulk Product cb25ebfe Clothing $64.10 64 0.9 74 BULK-85bbbe4b
19363 Bulk Product 71090682 Toys & Games $297.14 376 1.0 97 BULK-da8e66f3
19364 Bulk Product 332463d5 Books $319.79 256 4.9 62 BULK-0d9b6743
19365 Bulk Product fb2d60ec Electronics $934.38 480 3.0 48 BULK-3d6c4f6f
19366 Bulk Product dbf3d1f1 Sports & Outdoors $241.55 347 2.6 77 BULK-462b7d3b
19367 Bulk Product eda0b4c3 Home & Garden $562.41 279 0.4 39 BULK-23ef30f6
19368 Bulk Product 0523aac7 Toys & Games $131.85 77 2.3 37 BULK-1c6948e2
19369 Bulk Product 26f10ab7 Electronics $985.29 146 0.5 42 BULK-183428ca
19370 Bulk Product 9f3e8c32 Sports & Outdoors $842.64 461 4.5 75 BULK-9e35b1b0
19371 Bulk Product 4c577732 Toys & Games $822.76 209 3.9 58 BULK-1effe7bd
19372 Bulk Product 74520b19 Electronics $578.41 161 1.8 96 BULK-1bf15b35
19373 Bulk Product 1b7a5dfc Toys & Games $158.35 361 0.4 55 BULK-21729d97
19374 Bulk Product 94c4332b Home & Garden $947.46 248 0.1 49 BULK-747a2fe5
19375 Bulk Product 844ca520 Books $288.10 122 0.1 9 BULK-5c836cf8
19376 Bulk Product 2846d307 Home & Garden $76.61 283 2.7 78 BULK-f5de7782
19377 Bulk Product e9bc3f9c Toys & Games $34.97 498 1.6 99 BULK-c7154284
19378 Bulk Product b00f31f4 Clothing $612.99 327 5.0 77 BULK-0ae37808
19379 Bulk Product db832a95 Books $219.14 170 4.7 49 BULK-5efccc1f
19380 Bulk Product cbbcd662 Books $355.11 289 1.7 1 BULK-ace34b9f
19381 Bulk Product 25fc5b51 Home & Garden $973.64 122 0.3 45 BULK-c240cd59
19382 Bulk Product b0a61c1e Sports & Outdoors $319.04 149 3.3 41 BULK-7ead9b97
19383 Bulk Product 64b0d4b4 Toys & Games $930.79 231 1.1 31 BULK-7e879aaf
19384 Bulk Product fcf55dc1 Electronics $89.59 365 1.6 59 BULK-733e869f
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