Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

831 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 831 Results Showing 20751 - 20775 of 24441

ID Name Category Price Stock Rating Reviews SKU
21310 Bulk Product 89ee78da Home & Garden $395.72 431 2.5 56 BULK-0b5819a0
21311 Bulk Product c69c6545 Toys & Games $297.83 190 4.7 32 BULK-3b83f1c1
21312 Bulk Product 3933463d Clothing $741.59 53 0.5 59 BULK-33448587
21313 Bulk Product c44d5010 Sports & Outdoors $251.80 113 1.7 12 BULK-141fd33f
21314 Bulk Product 4c85051c Home & Garden $436.48 119 4.4 11 BULK-bf858d65
21315 Bulk Product 97ce95e2 Toys & Games $376.86 189 2.5 59 BULK-8f9e9eaa
21316 Bulk Product ab903128 Home & Garden $175.71 142 2.0 79 BULK-01441b20
21317 Bulk Product d34325e4 Sports & Outdoors $365.61 208 1.7 1 BULK-76a56261
21318 Bulk Product 382ab194 Toys & Games $690.26 248 3.6 88 BULK-e3eee91f
21319 Bulk Product 81278d60 Books $116.94 401 3.7 2 BULK-12462db7
21320 Bulk Product a28440b9 Home & Garden $98.17 333 4.1 33 BULK-3a0a4854
21321 Bulk Product e2007a45 Sports & Outdoors $625.97 110 0.3 4 BULK-64a189b3
21322 Bulk Product ad41577d Home & Garden $425.07 422 3.5 37 BULK-4992b541
21323 Bulk Product ea0a465b Toys & Games $93.33 238 0.0 66 BULK-0292beeb
21324 Bulk Product ba7aab5a Home & Garden $756.58 49 2.6 47 BULK-c9feb4aa
21325 Bulk Product 14fb675b Clothing $421.91 414 3.2 16 BULK-d22d2080
21326 Bulk Product adea3cae Books $1,006.59 193 2.3 53 BULK-99a0ae95
21327 Bulk Product 1d46404a Electronics $184.82 401 0.6 84 BULK-4d7fcd09
21328 Bulk Product 582e250e Home & Garden $902.42 374 2.6 77 BULK-878ed636
21329 Bulk Product fa7647c9 Electronics $204.77 56 1.4 46 BULK-b232dbc7
21330 Bulk Product 918768ff Sports & Outdoors $942.07 333 2.6 75 BULK-1a2a6bf0
21331 Bulk Product c0a53f2b Sports & Outdoors $31.58 154 4.8 97 BULK-62d3f3de
21332 Bulk Product 6b74bb29 Books $824.97 386 2.3 24 BULK-4fb9679b
21333 Bulk Product 9ebecf1f Toys & Games $325.48 189 1.4 3 BULK-f8696758
21334 Bulk Product b462791e Sports & Outdoors $136.33 77 3.8 77 BULK-8a05690c
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