Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

25

Current Page

457 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 457 Results Showing 11401 - 11425 of 24441

ID Name Category Price Stock Rating Reviews SKU
11960 Bulk Product dc424f30 Toys & Games $647.48 479 2.8 33 BULK-ee24d149
11961 Bulk Product 3cadf583 Electronics $948.02 282 0.6 39 BULK-662e21ee
11962 Bulk Product a7e43ce9 Clothing $535.99 385 2.5 90 BULK-351d31bd
11963 Bulk Product 7441be51 Toys & Games $843.41 4 3.9 26 BULK-1867c129
11964 Bulk Product 8313af8b Toys & Games $918.71 202 2.2 95 BULK-ba827ad9
11965 Bulk Product b3310e74 Home & Garden $518.39 151 0.1 30 BULK-84745da5
11966 Bulk Product 1b1ffaa9 Home & Garden $673.54 484 4.1 8 BULK-ac6e95d7
11967 Bulk Product c0c09890 Toys & Games $377.33 331 0.7 8 BULK-bd1c47dc
11968 Bulk Product a72d33c7 Toys & Games $878.94 442 2.6 4 BULK-859bd9da
11969 Bulk Product 2467c612 Books $233.10 129 2.0 96 BULK-86657476
11970 Bulk Product 3bc24c25 Sports & Outdoors $366.01 454 3.8 28 BULK-78a206c8
11971 Bulk Product 4662ebd7 Electronics $932.82 289 1.4 51 BULK-627cf9df
11972 Bulk Product c0984d15 Toys & Games $14.16 330 3.0 22 BULK-515003a8
11973 Bulk Product 2043e4ef Toys & Games $128.61 165 3.5 45 BULK-7a5674e2
11974 Bulk Product 6cbdb59b Home & Garden $302.20 292 4.9 40 BULK-c0a98286
11975 Bulk Product 8b092f08 Clothing $392.89 312 5.0 43 BULK-3274afd8
11976 Bulk Product b0d7cb3b Books $97.95 250 0.4 30 BULK-f283d173
11977 Bulk Product e8f535f4 Home & Garden $97.26 197 3.0 65 BULK-c4064878
11978 Bulk Product 9f26e3ab Electronics $950.73 487 4.0 96 BULK-4d61e69f
11979 Bulk Product 4c0498d9 Toys & Games $988.89 170 4.4 3 BULK-f5c0e3c3
11980 Bulk Product 764ebb78 Home & Garden $357.69 194 4.5 90 BULK-7694ac16
11981 Bulk Product de121a93 Clothing $814.10 465 0.5 9 BULK-93215a41
11982 Bulk Product 7f331929 Home & Garden $903.48 103 3.6 26 BULK-d6deee0a
11983 Bulk Product 70e8fe40 Toys & Games $644.93 471 1.4 32 BULK-b8899be1
11984 Bulk Product e74b9701 Clothing $617.19 200 3.5 33 BULK-b3fa2442
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