Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

8 ms

Page Size

25

Current Page

225 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 225 Results Showing 5601 - 5625 of 24441

ID Name Category Price Stock Rating Reviews SKU
6160 Bulk Product a9e50809 Sports & Outdoors $127.16 54 0.8 83 BULK-230bcde4
6161 Bulk Product dd18a02c Sports & Outdoors $507.03 475 2.0 88 BULK-7eae3d3a
6162 Bulk Product a5a20506 Home & Garden $700.34 488 2.0 44 BULK-d265410b
6163 Bulk Product ec1c9036 Home & Garden $75.60 34 2.3 13 BULK-eb66b767
6164 Bulk Product 38525b73 Toys & Games $230.09 93 4.0 11 BULK-1cc752aa
6165 Bulk Product 57049822 Sports & Outdoors $308.52 154 1.0 19 BULK-52f0223a
6166 Bulk Product e29d10a5 Books $829.83 173 1.0 30 BULK-e4b10c71
6167 Bulk Product 4e30662b Electronics $242.14 139 2.5 44 BULK-0f5300e4
6168 Bulk Product 9f0abb21 Clothing $89.93 380 2.1 69 BULK-55c267d9
6169 Bulk Product 054a46f8 Home & Garden $365.82 272 1.3 38 BULK-0817546c
6170 Bulk Product 0ccd94c8 Home & Garden $76.38 175 3.2 28 BULK-b3c9b05a
6171 Bulk Product 280a42e1 Sports & Outdoors $409.03 326 4.5 62 BULK-408bb471
6172 Bulk Product 34a4b743 Toys & Games $846.60 163 0.8 91 BULK-feb0ae4e
6173 Bulk Product b5392e49 Electronics $149.35 112 1.2 31 BULK-8bc511aa
6174 Bulk Product 44a99626 Electronics $318.71 19 3.6 20 BULK-94c27112
6175 Bulk Product d8140b9f Books $733.53 106 3.9 19 BULK-ced29fdc
6176 Bulk Product 04f3f48a Electronics $871.39 346 2.8 53 BULK-f2994810
6177 Bulk Product 036367fe Toys & Games $266.72 450 3.8 65 BULK-6361c744
6178 Bulk Product 57a139f5 Clothing $97.02 136 1.2 16 BULK-a5da39fc
6179 Bulk Product a0bfdf79 Electronics $997.62 20 1.3 18 BULK-77b3a3fe
6180 Bulk Product 1501cd0b Clothing $926.78 330 0.7 22 BULK-8de6cc81
6181 Bulk Product ebc8b5de Toys & Games $209.26 370 3.0 79 BULK-0f645b46
6182 Bulk Product 68b55845 Sports & Outdoors $432.64 295 4.7 5 BULK-0daec666
6183 Bulk Product 631cd6f0 Toys & Games $822.84 399 2.7 29 BULK-fb5ba630
6184 Bulk Product e61627c0 Toys & Games $993.72 152 3.0 32 BULK-b997f59a
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