Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

653 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 653 Results Showing 16301 - 16325 of 24441

ID Name Category Price Stock Rating Reviews SKU
16860 Bulk Product f837b793 Home & Garden $531.42 165 0.0 40 BULK-e6d58f05
16861 Bulk Product 6e029869 Toys & Games $470.57 302 3.5 97 BULK-94f03276
16862 Bulk Product ae2b645e Books $793.82 459 4.2 10 BULK-541c072e
16863 Bulk Product 12a04929 Toys & Games $270.53 282 4.5 74 BULK-88d5c76c
16864 Bulk Product 6aa6ce23 Sports & Outdoors $606.50 225 1.8 77 BULK-cd23362a
16865 Bulk Product e5dbe532 Sports & Outdoors $174.41 275 0.5 46 BULK-5b7f222d
16866 Bulk Product a1ae04ce Toys & Games $131.51 241 2.4 85 BULK-b1ac767b
16867 Bulk Product 64575376 Home & Garden $819.90 446 1.2 26 BULK-19972c66
16868 Bulk Product 0a62dcce Books $377.03 32 4.1 22 BULK-b9e94dd3
16869 Bulk Product 9694ca52 Electronics $696.31 323 1.4 67 BULK-10024ee3
16870 Bulk Product 346c30e8 Sports & Outdoors $114.56 370 2.8 93 BULK-807dd641
16871 Bulk Product a498c1e6 Electronics $390.61 147 2.3 58 BULK-7decba54
16872 Bulk Product 706ecdee Sports & Outdoors $690.61 44 5.0 60 BULK-6f3dcf9d
16873 Bulk Product b4e3cfb3 Home & Garden $581.74 25 3.1 54 BULK-78c223d1
16874 Bulk Product 87966d50 Toys & Games $781.11 287 4.0 72 BULK-3e13f456
16875 Bulk Product 0fe55974 Toys & Games $600.42 111 2.7 43 BULK-52ee2f63
16876 Bulk Product 72175a12 Electronics $15.58 277 2.3 56 BULK-3677eb0a
16877 Bulk Product eb70000a Sports & Outdoors $359.84 296 4.6 28 BULK-e64ed908
16878 Bulk Product 568d24fd Books $382.57 444 1.0 44 BULK-6a9de5b4
16879 Bulk Product bc5d940e Toys & Games $199.84 36 4.5 50 BULK-efe250ed
16880 Bulk Product 56e4fcc7 Home & Garden $356.39 139 0.6 12 BULK-05b80c04
16881 Bulk Product 5fb0213b Home & Garden $641.99 86 1.3 61 BULK-ced6c479
16882 Bulk Product bdd2ddab Electronics $538.01 367 4.7 99 BULK-1bad6174
16883 Bulk Product 4f47441f Home & Garden $591.48 8 4.7 48 BULK-65e40991
16884 Bulk Product 2147f0df Sports & Outdoors $358.64 322 2.6 80 BULK-214a3257
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