Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

24 ms

Page Size

25

Current Page

659 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 659 Results Showing 16451 - 16475 of 24441

ID Name Category Price Stock Rating Reviews SKU
17010 Bulk Product 26689b74 Books $473.06 290 4.4 21 BULK-140a3736
17011 Bulk Product 88bc2569 Clothing $174.59 478 3.3 11 BULK-41487664
17012 Bulk Product 606139a6 Books $281.28 186 0.6 6 BULK-eef70fbd
17013 Bulk Product 678153e7 Sports & Outdoors $758.16 424 2.7 40 BULK-821078b2
17014 Bulk Product e559a6e1 Books $224.56 305 0.9 68 BULK-cefd81ee
17015 Bulk Product d508c664 Sports & Outdoors $658.62 349 0.7 9 BULK-ec460aae
17016 Bulk Product f4639443 Clothing $514.58 359 2.6 76 BULK-bc6b4e64
17017 Bulk Product 9d7db265 Home & Garden $353.14 63 3.1 60 BULK-ef14c907
17018 Bulk Product ea11b2ee Books $994.36 364 2.2 12 BULK-d5375436
17019 Bulk Product 5401dbe2 Home & Garden $492.33 221 0.4 2 BULK-36918899
17020 Bulk Product 309f921d Clothing $505.19 346 3.2 11 BULK-37716e83
17021 Bulk Product bfc9e171 Home & Garden $214.08 195 2.4 15 BULK-3f76a668
17022 Bulk Product 54ae873e Clothing $454.30 346 3.8 72 BULK-735015c1
17023 Bulk Product d8675ad2 Home & Garden $732.68 86 3.0 89 BULK-d51a5453
17024 Bulk Product 81b396ec Toys & Games $912.44 424 1.7 93 BULK-fcd66a47
17025 Bulk Product d960ee17 Electronics $801.85 442 0.8 76 BULK-93270ff7
17026 Bulk Product e54b0bad Electronics $322.27 347 1.2 46 BULK-b4215e6b
17027 Bulk Product c65da8d1 Sports & Outdoors $856.13 189 3.2 79 BULK-524f0c24
17028 Bulk Product 63fd8792 Sports & Outdoors $147.01 134 3.6 66 BULK-b2e92b04
17029 Bulk Product 000558e6 Toys & Games $294.87 20 4.3 10 BULK-76693fe8
17030 Bulk Product 3da3d756 Home & Garden $92.29 223 4.3 12 BULK-76ae6a5b
17031 Bulk Product 6b555d0c Books $129.06 432 4.5 18 BULK-e29da7e5
17032 Bulk Product 5f128817 Books $977.16 222 3.4 98 BULK-27367a2c
17033 Bulk Product 0ecfa942 Home & Garden $371.04 285 0.9 4 BULK-ea3b4485
17034 Bulk Product c0aaad1f Electronics $23.22 442 3.7 69 BULK-3f49dbf6
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