Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

25

Current Page

603 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 603 Results Showing 15051 - 15075 of 24441

ID Name Category Price Stock Rating Reviews SKU
15610 Bulk Product a506d045 Clothing $906.96 268 1.2 57 BULK-17587289
15611 Bulk Product 354b7dce Clothing $195.58 9 2.9 59 BULK-d8efd09e
15612 Bulk Product ff078878 Toys & Games $692.75 237 0.3 6 BULK-b1e88cb4
15613 Bulk Product a5a6cee5 Home & Garden $545.85 335 1.8 26 BULK-a6d35380
15614 Bulk Product 95e454d4 Books $268.10 429 0.9 48 BULK-cb548f99
15615 Bulk Product 1dd4e4fc Home & Garden $996.50 291 4.0 62 BULK-d7aa5027
15616 Bulk Product f468de8e Home & Garden $218.71 74 3.1 62 BULK-a7a99c75
15617 Bulk Product 7eae7969 Sports & Outdoors $310.15 302 0.2 12 BULK-7e6c8e35
15618 Bulk Product b6766b7c Home & Garden $244.75 335 0.8 18 BULK-b7c4316e
15619 Bulk Product 23ec0802 Toys & Games $449.72 149 0.9 53 BULK-ffef9afa
15620 Bulk Product 414469d3 Clothing $426.50 110 0.8 92 BULK-07e0b388
15621 Bulk Product aea63844 Home & Garden $217.79 222 3.3 69 BULK-7550b464
15622 Bulk Product 1e6e7289 Books $246.90 356 2.6 27 BULK-ac357848
15623 Bulk Product bd6f551c Books $629.19 324 3.7 46 BULK-ace6626e
15624 Bulk Product c30aaebd Toys & Games $177.71 348 1.1 19 BULK-4566deb0
15625 Bulk Product 94e3edee Home & Garden $238.07 198 0.6 29 BULK-5d5e120f
15626 Bulk Product d7328d84 Books $835.37 299 3.6 10 BULK-d419f674
15627 Bulk Product 6f809c1a Books $591.83 361 0.5 85 BULK-34caae55
15628 Bulk Product 4819458f Sports & Outdoors $374.51 165 2.3 60 BULK-a628d2c3
15629 Bulk Product 605bec21 Home & Garden $686.68 158 1.1 1 BULK-40a58f6a
15630 Bulk Product cc29d72c Toys & Games $720.74 496 2.8 23 BULK-5efc256d
15631 Bulk Product d8d769d7 Clothing $176.02 404 2.1 73 BULK-b728525a
15632 Bulk Product bd2ee68b Sports & Outdoors $869.80 1 2.4 23 BULK-7638d784
15633 Bulk Product 66ed4509 Electronics $105.80 52 4.3 44 BULK-521936cf
15634 Bulk Product b10e84ff Home & Garden $947.50 123 1.6 35 BULK-d24a6590
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