Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

47 ms

Page Size

25

Current Page

876 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 876 Results Showing 21876 - 21900 of 24441

ID Name Category Price Stock Rating Reviews SKU
22435 Bulk Product 6e3e15c3 Books $415.15 92 1.3 75 BULK-a243ac49
22436 Bulk Product da5166e9 Clothing $799.59 310 1.2 20 BULK-2ecd6b20
22437 Bulk Product 81be08c7 Clothing $66.62 1 4.4 56 BULK-cb1c0fdd
22438 Bulk Product 92effe12 Sports & Outdoors $870.41 344 3.4 91 BULK-01c88a96
22439 Bulk Product 6062191e Clothing $337.38 200 2.9 90 BULK-8c15be3a
22440 Bulk Product f62e4db2 Clothing $312.54 204 4.9 96 BULK-d38fbbb6
22441 Bulk Product e9182f2b Toys & Games $285.70 494 0.7 77 BULK-035c21da
22442 Bulk Product 39df0f36 Electronics $205.84 277 3.5 97 BULK-9d511167
22443 Bulk Product 813cc140 Clothing $140.72 481 4.6 43 BULK-d0b0908d
22444 Bulk Product 9d5a4ae6 Toys & Games $560.64 210 3.0 85 BULK-cdb82370
22445 Bulk Product 6a016373 Home & Garden $733.38 116 1.0 5 BULK-1d932370
22446 Bulk Product 686b84f4 Toys & Games $660.29 406 1.7 26 BULK-6054d924
22447 Bulk Product 84c7ce35 Books $712.00 372 4.6 31 BULK-51199d5d
22448 Bulk Product 68c935a1 Home & Garden $19.18 270 1.5 19 BULK-daec03c8
22449 Bulk Product 00e698cb Clothing $163.63 50 0.4 99 BULK-b692200b
22450 Bulk Product 1b1f86ec Books $901.83 369 0.6 86 BULK-de902dcd
22451 Bulk Product e1adc00f Electronics $643.80 394 3.4 73 BULK-b1cca378
22452 Bulk Product e9f2f602 Home & Garden $540.24 279 1.3 32 BULK-43bfa2e5
22453 Bulk Product d29b5b27 Clothing $199.28 180 0.9 69 BULK-eb4c0b3d
22454 Bulk Product 04bc7b33 Books $1,002.93 419 4.3 97 BULK-42eb249d
22455 Bulk Product deba7fee Electronics $604.25 473 2.3 71 BULK-6fb48c33
22456 Bulk Product 21821dd6 Clothing $653.17 226 0.7 78 BULK-f4b8cdda
22457 Bulk Product 5f63f4d5 Sports & Outdoors $549.05 14 2.5 98 BULK-1d81725f
22458 Bulk Product 2f39e399 Home & Garden $189.20 352 2.9 16 BULK-8388f09a
22459 Bulk Product 51615ce1 Sports & Outdoors $72.26 383 1.2 66 BULK-eb6a0a2d
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