Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

838 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 838 Results Showing 20926 - 20950 of 24441

ID Name Category Price Stock Rating Reviews SKU
21485 Bulk Product 4a51267b Electronics $65.22 178 4.7 50 BULK-bbc6530d
21486 Bulk Product d5d8e01f Books $709.68 35 1.1 25 BULK-68c2031e
21487 Bulk Product 8d2b3ed3 Clothing $458.39 158 2.3 44 BULK-959fcd43
21488 Bulk Product d94a0a94 Books $907.00 42 0.7 19 BULK-a2f10ac9
21489 Bulk Product aedc397c Clothing $308.84 217 1.3 81 BULK-c8332a69
21490 Bulk Product 4526deb8 Clothing $991.69 445 1.8 12 BULK-c9755fa3
21491 Bulk Product fb332d99 Sports & Outdoors $151.58 328 2.8 85 BULK-c0c56e09
21492 Bulk Product 73de1b40 Books $502.87 76 1.4 9 BULK-aea24bb3
21493 Bulk Product d62ac6f1 Clothing $178.45 378 2.2 41 BULK-4756a907
21494 Bulk Product 105e0e64 Clothing $191.10 55 3.2 35 BULK-fa34e5df
21495 Bulk Product fbdab4c1 Clothing $839.72 446 2.4 20 BULK-df0101a8
21496 Bulk Product 0401156b Electronics $728.06 357 3.7 66 BULK-af00a6ae
21497 Bulk Product 698c6370 Toys & Games $537.08 477 2.5 53 BULK-deae2e1e
21498 Bulk Product 86bdc7b8 Electronics $165.85 84 0.5 14 BULK-91b7754d
21499 Bulk Product b99e603a Electronics $909.91 15 1.5 27 BULK-7b3aeda6
21500 Bulk Product a912bcd9 Electronics $662.84 456 4.9 8 BULK-1e7e8e22
21501 Bulk Product 4a9cce8c Electronics $811.67 334 0.9 75 BULK-24cc04be
21502 Bulk Product 2a69fbf9 Toys & Games $991.94 280 0.8 80 BULK-1f6c042c
21503 Bulk Product f8490551 Electronics $446.30 291 4.3 2 BULK-6bab0a2a
21504 Bulk Product 722bc68d Home & Garden $801.00 335 0.6 15 BULK-fc486360
21505 Bulk Product 23f2a934 Toys & Games $754.09 27 4.1 59 BULK-d8b07957
21506 Bulk Product a41adc6b Electronics $166.56 362 3.4 58 BULK-f5d176c7
21507 Bulk Product 6884d73e Sports & Outdoors $242.34 100 2.0 72 BULK-5affd2d9
21508 Bulk Product a1f14475 Toys & Games $53.26 12 3.0 31 BULK-5e42558a
21509 Bulk Product 9a928c07 Toys & Games $516.37 424 3.9 77 BULK-660a2b2c
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