Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

25

Current Page

630 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 630 Results Showing 15726 - 15750 of 24441

ID Name Category Price Stock Rating Reviews SKU
16285 Bulk Product 3a7a9ff5 Books $498.92 103 1.0 64 BULK-f332d009
16286 Bulk Product 933fa05f Electronics $725.50 176 4.4 35 BULK-c4e56627
16287 Bulk Product ac0fe267 Clothing $91.64 397 1.0 57 BULK-2652c0fa
16288 Bulk Product fa606127 Clothing $416.95 366 4.5 2 BULK-0eb4385a
16289 Bulk Product 8cce3588 Home & Garden $692.19 138 3.9 26 BULK-9c7dc000
16290 Bulk Product c2ec37ab Clothing $42.46 296 0.4 78 BULK-34c62de5
16291 Bulk Product a3e72873 Sports & Outdoors $164.19 238 1.2 62 BULK-6170f140
16292 Bulk Product cdc2e545 Clothing $112.13 238 4.5 51 BULK-4da9c7ce
16293 Bulk Product 779a6b6f Sports & Outdoors $737.59 210 2.4 34 BULK-80300221
16294 Bulk Product 7e60908c Home & Garden $93.44 311 2.7 24 BULK-a4d8e3fe
16295 Bulk Product afa4035a Electronics $356.34 498 4.5 47 BULK-0377a180
16296 Bulk Product 776aef02 Clothing $428.53 467 0.1 81 BULK-3333d910
16297 Bulk Product 2d4c78e8 Home & Garden $300.00 380 5.0 25 BULK-283e0b79
16298 Bulk Product 5f0be19b Toys & Games $662.32 52 3.4 97 BULK-2005fac0
16299 Bulk Product 8bece07c Clothing $168.77 335 4.2 73 BULK-5c0b0cc1
16300 Bulk Product c3d67025 Home & Garden $598.79 36 1.8 46 BULK-35b524dc
16301 Bulk Product 81728c02 Sports & Outdoors $258.87 364 1.0 34 BULK-1e1baa5a
16302 Bulk Product 646a6fa1 Books $932.86 78 3.1 25 BULK-42968db9
16303 Bulk Product bf8bd82f Toys & Games $719.21 39 0.7 55 BULK-6d7f77ad
16304 Bulk Product a736b5ec Clothing $109.80 111 2.3 84 BULK-928a9dae
16305 Bulk Product 232dea33 Electronics $297.14 295 0.8 99 BULK-fb536d4b
16306 Bulk Product 702d541b Sports & Outdoors $413.88 115 1.4 96 BULK-48a9460e
16307 Bulk Product 81feb13f Sports & Outdoors $163.53 62 0.4 20 BULK-74b4e7d8
16308 Bulk Product 5f228587 Home & Garden $985.22 411 4.2 4 BULK-33075ba2
16309 Bulk Product 6453befb Books $621.24 491 0.7 44 BULK-d00cfda5
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