Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

26 ms

Page Size

25

Current Page

670 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 670 Results Showing 16726 - 16750 of 24441

ID Name Category Price Stock Rating Reviews SKU
17285 Bulk Product 320c9374 Sports & Outdoors $377.88 60 1.5 85 BULK-383a27c2
17286 Bulk Product 18841faa Books $756.02 480 2.1 11 BULK-ebe7afaf
17287 Bulk Product 5744f562 Sports & Outdoors $860.22 379 0.3 61 BULK-085ae601
17288 Bulk Product d7b541ea Home & Garden $553.45 150 0.2 54 BULK-b129cd68
17289 Bulk Product 4d4a4925 Home & Garden $396.15 227 1.3 51 BULK-869c3424
17290 Bulk Product d0ac5c5b Clothing $852.65 496 2.0 84 BULK-1e2f7fd2
17291 Bulk Product 75c45fde Books $655.96 178 1.5 44 BULK-484e035f
17292 Bulk Product 7787fad4 Electronics $363.63 267 0.4 41 BULK-b450d61b
17293 Bulk Product f8f6c1df Sports & Outdoors $344.41 238 0.5 92 BULK-b6246f6a
17294 Bulk Product cc2e7ce2 Electronics $280.41 138 3.1 81 BULK-2f72d2e2
17295 Bulk Product 06ea4f87 Books $994.37 176 1.2 50 BULK-a0f03816
17296 Bulk Product ce0ae408 Home & Garden $837.05 57 1.0 83 BULK-345d09d9
17297 Bulk Product 5931976e Books $592.72 141 2.2 83 BULK-d3b5dad1
17298 Bulk Product 52857baf Clothing $296.40 216 3.4 22 BULK-bb3b2771
17299 Bulk Product e19e4ccb Toys & Games $966.63 177 4.2 41 BULK-eda12ef2
17300 Bulk Product a5d99113 Clothing $58.10 405 0.3 46 BULK-eebefc4f
17301 Bulk Product d6002cbb Books $777.59 405 3.2 39 BULK-2b45e2aa
17302 Bulk Product 65f29d86 Sports & Outdoors $522.05 138 4.3 11 BULK-ef9966da
17303 Bulk Product 93b1d575 Books $659.51 160 3.3 78 BULK-8b1071cc
17304 Bulk Product ee00f5e7 Electronics $551.95 391 4.2 33 BULK-ec9aae16
17305 Bulk Product bc2491b7 Sports & Outdoors $648.99 347 3.0 40 BULK-6c9f0b5e
17306 Bulk Product 1bbf7208 Toys & Games $405.00 484 4.1 0 BULK-edeca44e
17307 Bulk Product 61cfda83 Electronics $788.89 124 0.6 26 BULK-03be09b2
17308 Bulk Product 9e68b947 Books $890.39 238 0.4 37 BULK-c9932a55
17309 Bulk Product c826c79c Clothing $851.22 493 1.2 24 BULK-e961d1f1
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