Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

40 ms

Page Size

25

Current Page

808 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 808 Results Showing 20176 - 20200 of 24441

ID Name Category Price Stock Rating Reviews SKU
20735 Bulk Product 05fe2e1b Toys & Games $240.80 421 0.3 13 BULK-f41c0d4e
20736 Bulk Product 6b2d1d71 Sports & Outdoors $951.29 206 1.8 95 BULK-b34ba945
20737 Bulk Product 11910172 Toys & Games $642.04 284 3.4 92 BULK-fcd127d0
20738 Bulk Product 223a4b45 Toys & Games $40.58 202 4.7 36 BULK-b360c2e7
20739 Bulk Product f12f7832 Books $349.20 359 1.5 96 BULK-dea2be64
20740 Bulk Product 125bd862 Electronics $811.89 387 2.9 25 BULK-e98fcb83
20741 Bulk Product 045bf79b Sports & Outdoors $258.97 212 1.9 78 BULK-8e6385e7
20742 Bulk Product 9fbe1dd5 Sports & Outdoors $212.32 482 4.7 93 BULK-9e7fc798
20743 Bulk Product 6777a40f Electronics $802.88 41 1.6 54 BULK-21ca96bf
20744 Bulk Product 031bbeeb Electronics $718.60 127 0.8 72 BULK-e3d00da1
20745 Bulk Product d4e5b508 Electronics $580.46 467 3.3 92 BULK-0bb08e09
20746 Bulk Product 2849a272 Clothing $247.21 40 0.0 91 BULK-7cbb2734
20747 Bulk Product 903e6a64 Sports & Outdoors $77.47 360 1.5 70 BULK-844b36c9
20748 Bulk Product 79c37550 Electronics $270.20 230 2.4 36 BULK-a9eeac38
20749 Bulk Product a1af5f2e Toys & Games $307.88 489 4.0 58 BULK-64cf2e5b
20750 Bulk Product bf279d33 Books $67.99 460 1.7 13 BULK-099b5297
20751 Bulk Product 22e19909 Electronics $383.26 379 3.2 21 BULK-0fe4979e
20752 Bulk Product 04172c54 Books $637.19 389 4.6 95 BULK-c26d599e
20753 Bulk Product e5e50ac4 Sports & Outdoors $35.64 344 0.6 11 BULK-39adf4bf
20754 Bulk Product 8e181b00 Books $971.00 123 5.0 98 BULK-f1595aac
20755 Bulk Product 34a3db57 Books $687.52 373 1.1 49 BULK-ad091adf
20756 Bulk Product a9f38c2b Electronics $785.48 473 4.3 20 BULK-b7f4ff8d
20757 Bulk Product 37d4de64 Books $128.13 214 1.7 3 BULK-de0b1b5d
20758 Bulk Product 68b0e413 Sports & Outdoors $720.51 485 4.8 6 BULK-a3c2e1ac
20759 Bulk Product d13fed93 Electronics $406.20 149 3.3 30 BULK-0db2675e
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