Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

25

Current Page

492 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 492 Results Showing 12276 - 12300 of 24441

ID Name Category Price Stock Rating Reviews SKU
12835 Bulk Product 4fe89167 Home & Garden $909.49 182 4.1 63 BULK-49fb6d82
12836 Bulk Product 9bfea01f Books $505.33 141 3.5 96 BULK-41fc9b54
12837 Bulk Product d59ce6fe Books $543.50 406 4.7 73 BULK-0c142fd0
12838 Bulk Product 9ca96080 Home & Garden $913.50 146 0.3 78 BULK-03f931b3
12839 Bulk Product f82f0b4b Home & Garden $26.12 68 1.8 78 BULK-52ebc787
12840 Bulk Product 3d270fb4 Toys & Games $345.67 162 0.2 11 BULK-6a39d16f
12841 Bulk Product ddd63976 Sports & Outdoors $947.84 319 4.4 22 BULK-6250384a
12842 Bulk Product 55ec5e79 Toys & Games $432.92 386 0.6 38 BULK-82c3642d
12843 Bulk Product e6bbd470 Home & Garden $592.52 146 4.5 71 BULK-859fd76a
12844 Bulk Product dbfed747 Electronics $116.67 493 4.3 71 BULK-03b8f58a
12845 Bulk Product df129bb3 Books $651.18 171 0.4 10 BULK-b63c20c7
12846 Bulk Product 5f60fe5d Sports & Outdoors $836.45 350 0.2 34 BULK-6ce86474
12847 Bulk Product b7fa5b54 Toys & Games $709.85 142 2.3 44 BULK-7f875337
12848 Bulk Product 102d5bc5 Home & Garden $410.09 466 4.8 80 BULK-e1c87be4
12849 Bulk Product c9f12056 Toys & Games $267.28 63 4.3 34 BULK-50c881b0
12850 Bulk Product 1a351989 Books $155.57 437 4.4 22 BULK-ce3e7b87
12851 Bulk Product b9978228 Home & Garden $877.03 113 0.7 43 BULK-b783246f
12852 Bulk Product e2444824 Books $126.93 320 0.2 10 BULK-95f9d911
12853 Bulk Product e6cd7307 Toys & Games $228.07 1 3.6 23 BULK-05ae10e0
12854 Bulk Product c0752dc2 Sports & Outdoors $59.16 448 2.1 57 BULK-7c5bdf9a
12855 Bulk Product e204d362 Clothing $372.41 436 2.3 28 BULK-a4433a7e
12856 Bulk Product f9096ce7 Home & Garden $47.99 182 0.3 34 BULK-2e3d74ed
12857 Bulk Product e55ea72d Home & Garden $992.87 446 4.4 25 BULK-50712dea
12858 Bulk Product 47e41524 Clothing $272.55 370 1.4 64 BULK-251d9384
12859 Bulk Product ca66d4f5 Clothing $939.41 470 3.9 88 BULK-875ef6c7
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