Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

405 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 405 Results Showing 10101 - 10125 of 24441

ID Name Category Price Stock Rating Reviews SKU
10660 Bulk Product 7e586476 Clothing $445.46 97 1.2 77 BULK-8daa7aa8
10661 Bulk Product 0e16e342 Toys & Games $417.03 2 2.1 33 BULK-b16f8a58
10662 Bulk Product 6e2041bb Books $224.66 83 1.2 26 BULK-cea8e0ea
10663 Bulk Product b153d877 Home & Garden $867.05 83 1.8 50 BULK-0b7e4832
10664 Bulk Product a1547619 Sports & Outdoors $928.30 75 1.3 0 BULK-ddd0180a
10665 Bulk Product 2b4f8b72 Toys & Games $471.64 61 3.1 97 BULK-5b2dd21c
10666 Bulk Product 8cced5f4 Home & Garden $783.53 227 3.4 42 BULK-e6bc51e9
10667 Bulk Product c586219b Books $289.22 373 1.9 39 BULK-a51030ef
10668 Bulk Product e5fc6de3 Home & Garden $378.43 327 2.9 42 BULK-5fe63521
10669 Bulk Product ee92d041 Home & Garden $598.25 229 2.5 93 BULK-2303b016
10670 Bulk Product 028f9ac4 Electronics $875.48 74 1.8 69 BULK-8bc2ad55
10671 Bulk Product 186883c7 Home & Garden $18.02 167 2.6 93 BULK-bf72ae7c
10672 Bulk Product d858b678 Clothing $149.03 150 0.5 34 BULK-48704956
10673 Bulk Product d5cae749 Clothing $18.32 50 4.2 83 BULK-5c303a33
10674 Bulk Product 5ebef3ca Books $431.80 337 3.5 64 BULK-49722e4d
10675 Bulk Product cfdb53c1 Home & Garden $792.62 108 1.9 94 BULK-fbbd98f5
10676 Bulk Product e21988c8 Toys & Games $576.10 95 4.4 87 BULK-aca4aa04
10677 Bulk Product 086af221 Clothing $357.28 484 0.6 89 BULK-cde46f81
10678 Bulk Product 865266ef Clothing $193.50 211 3.6 20 BULK-8ca5e3ac
10679 Bulk Product 84450dbb Toys & Games $582.14 313 0.0 13 BULK-055cfa5a
10680 Bulk Product f5509f5d Books $406.72 489 2.4 98 BULK-dbf306ea
10681 Bulk Product d5e5afb9 Books $132.09 250 0.6 78 BULK-2e49d964
10682 Bulk Product 186d9b36 Electronics $920.58 493 2.0 9 BULK-02666f8a
10683 Bulk Product fc7a415c Clothing $1,008.62 387 2.1 82 BULK-0c9dac21
10684 Bulk Product b2e3b7e6 Clothing $621.22 342 2.2 34 BULK-7e38bfd8
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