Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

355 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 355 Results Showing 8851 - 8875 of 24441

ID Name Category Price Stock Rating Reviews SKU
9410 Bulk Product bd3ff997 Books $83.01 158 2.3 88 BULK-98477f92
9411 Bulk Product b609c2c2 Sports & Outdoors $115.62 111 2.8 25 BULK-669fa0af
9412 Bulk Product 0c22b320 Clothing $140.50 14 1.3 39 BULK-e3121c4a
9413 Bulk Product 63ba6c49 Home & Garden $304.65 427 3.1 43 BULK-69b59ad0
9414 Bulk Product 58178ecb Electronics $56.57 470 3.9 89 BULK-902e4cb6
9415 Bulk Product fb92ddae Sports & Outdoors $540.04 344 0.7 5 BULK-cb693cd3
9416 Bulk Product 7e089f36 Toys & Games $362.09 192 0.5 44 BULK-863c08db
9417 Bulk Product c35a530e Home & Garden $414.56 12 4.9 67 BULK-07d32345
9418 Bulk Product a0e7cb78 Clothing $898.49 39 1.7 16 BULK-8d1398c2
9419 Bulk Product b078af96 Electronics $200.65 301 2.1 32 BULK-7c739edc
9420 Bulk Product efb7fb37 Books $391.80 254 0.3 52 BULK-85504627
9421 Bulk Product 5ff9e41d Books $808.33 287 3.8 11 BULK-1ec7eba4
9422 Bulk Product c4a6587e Books $386.65 236 2.1 29 BULK-cf0c48a6
9423 Bulk Product a38dc479 Clothing $914.45 320 3.3 99 BULK-aca5de10
9424 Bulk Product f967dd8d Electronics $112.76 78 0.2 63 BULK-776a2767
9425 Bulk Product 244c5279 Toys & Games $721.03 421 4.9 74 BULK-d7797906
9426 Bulk Product d05adcd2 Home & Garden $93.57 70 1.7 92 BULK-c342dd4f
9427 Bulk Product 1c1e94a0 Clothing $627.34 3 1.6 33 BULK-1db46161
9428 Bulk Product 86326378 Clothing $616.88 346 4.7 51 BULK-5612344f
9429 Bulk Product 137be9ba Home & Garden $203.56 211 1.2 4 BULK-73ada5d0
9430 Bulk Product 379accb2 Sports & Outdoors $306.31 285 2.9 69 BULK-58d3cdfe
9431 Bulk Product dfb353aa Sports & Outdoors $117.23 403 2.7 43 BULK-4a7b1ab8
9432 Bulk Product dd02088c Books $65.11 495 2.1 91 BULK-1b6bb7fb
9433 Bulk Product f9803adc Electronics $943.44 220 1.8 16 BULK-ff860d0b
9434 Bulk Product 97a581c8 Electronics $937.52 163 4.9 3 BULK-3345d84a
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