Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

513 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 513 Results Showing 12801 - 12825 of 24441

ID Name Category Price Stock Rating Reviews SKU
13360 Bulk Product 1df9dfd9 Clothing $732.90 52 3.0 55 BULK-5134b3d1
13361 Bulk Product 6a5c26d9 Books $405.72 33 4.7 92 BULK-37968515
13362 Bulk Product 7f9b3fad Home & Garden $790.02 97 1.7 97 BULK-5658e55c
13363 Bulk Product a898fed4 Electronics $651.17 147 4.5 49 BULK-a6b633ee
13364 Bulk Product 6373f736 Home & Garden $63.68 45 2.1 54 BULK-8ac0c125
13365 Bulk Product 491a84bb Home & Garden $777.83 378 1.2 36 BULK-3420ca0e
13366 Bulk Product 00fb8744 Sports & Outdoors $945.28 476 0.9 9 BULK-781dae20
13367 Bulk Product c26eae84 Home & Garden $50.97 244 0.1 42 BULK-8ce0b243
13368 Bulk Product b6129c00 Clothing $160.44 106 1.9 95 BULK-61a549bb
13369 Bulk Product 6364213a Electronics $104.77 253 3.7 67 BULK-43175b6f
13370 Bulk Product 66a64270 Toys & Games $136.76 85 3.4 69 BULK-8baf2a02
13371 Bulk Product bf6411ba Sports & Outdoors $18.57 164 3.5 69 BULK-56656c6d
13372 Bulk Product 87e1c81d Sports & Outdoors $274.03 382 1.5 22 BULK-526b00f9
13373 Bulk Product ef54ee9e Clothing $787.60 131 3.7 65 BULK-683581af
13374 Bulk Product 0ea631b1 Electronics $209.14 369 3.7 23 BULK-8e5e20c7
13375 Bulk Product 437b01a9 Books $53.17 291 4.1 78 BULK-06950725
13376 Bulk Product f8533ad5 Electronics $725.50 123 2.5 54 BULK-27f0a4b8
13377 Bulk Product 2d0a8b6d Home & Garden $717.12 166 1.3 99 BULK-bbc73ab4
13378 Bulk Product 99e69beb Toys & Games $401.20 107 0.1 56 BULK-f6d3be53
13379 Bulk Product 690d14cf Books $587.80 93 0.9 74 BULK-a9ecff77
13380 Bulk Product 15d1938b Sports & Outdoors $570.73 54 1.3 17 BULK-0f927677
13381 Bulk Product af2705f7 Clothing $414.67 411 3.1 64 BULK-9351fc08
13382 Bulk Product 21c61568 Books $111.33 231 3.1 96 BULK-e8a94e1b
13383 Bulk Product 2ad9b602 Clothing $484.64 154 4.7 51 BULK-52812e89
13384 Bulk Product 1b51cdce Books $405.21 231 0.5 5 BULK-9d739bd4
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