Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

22 ms

Page Size

25

Current Page

622 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 622 Results Showing 15526 - 15550 of 24441

ID Name Category Price Stock Rating Reviews SKU
16085 Bulk Product 7b3daee0 Home & Garden $278.86 111 0.1 68 BULK-07bb2bd2
16086 Bulk Product f3578889 Home & Garden $80.09 483 4.7 14 BULK-d6808e06
16087 Bulk Product 018fa136 Home & Garden $105.57 476 3.4 73 BULK-097a082f
16088 Bulk Product c5744c76 Toys & Games $1,000.20 196 1.8 38 BULK-50c02aa9
16089 Bulk Product 06a73f4f Home & Garden $432.33 171 3.9 4 BULK-27a4e321
16090 Bulk Product 4db86898 Electronics $826.32 412 4.9 34 BULK-dbc965fd
16091 Bulk Product 7f7df853 Books $518.43 358 2.8 7 BULK-a8ad4c4b
16092 Bulk Product aa86b3c1 Sports & Outdoors $301.45 485 3.7 8 BULK-e936b2b5
16093 Bulk Product c6256ed5 Toys & Games $185.25 232 0.5 33 BULK-9b74f245
16094 Bulk Product 7b76fa9d Toys & Games $164.33 363 0.9 87 BULK-396d29a2
16095 Bulk Product 90328f9c Sports & Outdoors $506.38 406 4.0 92 BULK-08c8a747
16096 Bulk Product 1ecb4435 Toys & Games $496.76 493 4.2 9 BULK-2b923e59
16097 Bulk Product 4c75e64e Clothing $457.08 71 5.0 44 BULK-85b254d9
16098 Bulk Product b8862bf4 Electronics $719.33 341 1.5 72 BULK-e8aeee8b
16099 Bulk Product 1ac1b254 Books $18.13 370 3.1 52 BULK-18f0d82b
16100 Bulk Product cdb50d1b Clothing $1,008.15 409 1.7 2 BULK-b01d1ac0
16101 Bulk Product 38a19a97 Home & Garden $267.08 193 4.4 20 BULK-e9fae84e
16102 Bulk Product 9638191a Electronics $351.33 34 3.5 33 BULK-7cf63518
16103 Bulk Product 0666341d Clothing $628.43 415 4.5 93 BULK-a30b3e0b
16104 Bulk Product 0727bc81 Home & Garden $720.85 250 0.5 63 BULK-a66c1f04
16105 Bulk Product ae5524eb Home & Garden $157.44 168 0.6 93 BULK-fb125c5b
16106 Bulk Product 7c2dba64 Clothing $482.37 107 1.3 30 BULK-3f94313c
16107 Bulk Product a5785f43 Sports & Outdoors $763.52 211 3.0 75 BULK-86b7f8bb
16108 Bulk Product a398ff3d Toys & Games $759.73 198 4.9 17 BULK-d638da1b
16109 Bulk Product 128daeae Books $971.24 151 1.0 37 BULK-41beae8f
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