Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

52 ms

Page Size

25

Current Page

787 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 787 Results Showing 19651 - 19675 of 24441

ID Name Category Price Stock Rating Reviews SKU
20210 Bulk Product 3bae8afa Clothing $450.77 222 1.9 0 BULK-8bf9dfbf
20211 Bulk Product ddaed4b4 Books $147.74 499 3.5 51 BULK-9d436179
20212 Bulk Product 12fde920 Books $777.17 92 0.1 19 BULK-975a216d
20213 Bulk Product 74430399 Home & Garden $43.54 348 4.7 35 BULK-95db5344
20214 Bulk Product 390f2c2f Books $452.01 151 0.2 44 BULK-1667c424
20215 Bulk Product 12661ed1 Home & Garden $730.03 251 3.4 41 BULK-35daa4bd
20216 Bulk Product 14a0b2e3 Electronics $323.43 42 1.3 4 BULK-5f600e03
20217 Bulk Product ee8897f5 Sports & Outdoors $461.11 122 2.4 94 BULK-c1ed546e
20218 Bulk Product a5454795 Toys & Games $263.84 368 2.8 40 BULK-ae577124
20219 Bulk Product 75093f43 Clothing $513.27 62 2.7 86 BULK-1966d34f
20220 Bulk Product 300e9839 Electronics $321.64 238 0.8 45 BULK-f78ad8b3
20221 Bulk Product e8a825ab Books $116.05 202 1.5 52 BULK-b3ed2019
20222 Bulk Product 7116fb45 Sports & Outdoors $791.10 85 3.9 95 BULK-0993e3e0
20223 Bulk Product b7a94e4c Books $320.46 269 2.7 97 BULK-9380897c
20224 Bulk Product eebaea74 Home & Garden $582.95 342 3.5 11 BULK-b15d634d
20225 Bulk Product 0df9870e Sports & Outdoors $860.40 110 0.9 22 BULK-972f4448
20226 Bulk Product d0a219b4 Books $435.50 433 0.3 81 BULK-c192b608
20227 Bulk Product 362818bd Electronics $60.74 32 3.2 56 BULK-6d015dc3
20228 Bulk Product a497d3a7 Sports & Outdoors $758.11 404 3.8 78 BULK-e5f293b4
20229 Bulk Product f445c99e Clothing $850.41 472 1.1 7 BULK-24ebb0eb
20230 Bulk Product 25882a08 Sports & Outdoors $604.87 80 3.4 68 BULK-8da3c326
20231 Bulk Product 1668b110 Electronics $191.85 387 1.3 65 BULK-7ace41bc
20232 Bulk Product 85f3f023 Electronics $453.85 228 4.9 82 BULK-90bbc590
20233 Bulk Product 930b16d5 Toys & Games $116.72 284 2.0 65 BULK-a2626dfa
20234 Bulk Product 8f685646 Books $619.29 497 2.5 81 BULK-4426bfd6
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