Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

610 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 610 Results Showing 15226 - 15250 of 24441

ID Name Category Price Stock Rating Reviews SKU
15785 Bulk Product ea31562b Sports & Outdoors $54.19 467 1.0 72 BULK-22ce19db
15786 Bulk Product 34465f59 Books $395.99 476 3.5 70 BULK-a3ec4766
15787 Bulk Product fa4c5cb2 Clothing $829.01 182 0.8 87 BULK-50375315
15788 Bulk Product e68f75d7 Electronics $753.30 10 4.5 8 BULK-f3aea6e3
15789 Bulk Product 764cb1a4 Home & Garden $686.22 87 0.3 78 BULK-f91393ca
15790 Bulk Product ca8cfc1c Home & Garden $923.54 254 1.7 81 BULK-e7cdbc8c
15791 Bulk Product ae12be23 Home & Garden $493.60 133 3.7 38 BULK-6ad44002
15792 Bulk Product 977243f7 Sports & Outdoors $796.33 81 2.1 39 BULK-fabffdbe
15793 Bulk Product 214da8d6 Books $893.02 386 4.0 94 BULK-d213ecbb
15794 Bulk Product b81dfb40 Clothing $904.45 108 0.9 33 BULK-95e0c896
15795 Bulk Product bbcb5318 Toys & Games $403.80 374 1.5 22 BULK-ff03e878
15796 Bulk Product 1d8849cf Toys & Games $217.05 329 3.6 86 BULK-12e3b551
15797 Bulk Product 305008b6 Sports & Outdoors $873.53 43 3.3 31 BULK-d754d0ce
15798 Bulk Product bda64a98 Clothing $237.62 42 2.4 29 BULK-642baee3
15799 Bulk Product 06fa61fa Sports & Outdoors $14.58 405 2.9 7 BULK-df99e795
15800 Bulk Product 66f43055 Toys & Games $20.38 260 3.9 41 BULK-a21a7816
15801 Bulk Product 09f23032 Clothing $57.84 306 1.5 16 BULK-8cd38f83
15802 Bulk Product fe0e3346 Electronics $965.29 419 0.4 13 BULK-4bdb6f3e
15803 Bulk Product 2377b21a Books $454.27 364 0.3 33 BULK-32d3b2d3
15804 Bulk Product 2f4e750f Clothing $903.36 396 3.7 62 BULK-bc44e688
15805 Bulk Product 65a6b46b Electronics $608.03 165 1.4 19 BULK-57d7f768
15806 Bulk Product 044e3bdd Home & Garden $294.81 336 2.7 70 BULK-c6b5c0c0
15807 Bulk Product 14a4dd07 Books $957.74 480 4.1 81 BULK-5b1780ca
15808 Bulk Product b70922f2 Books $213.73 451 1.4 71 BULK-421c02ba
15809 Bulk Product 473d4e00 Electronics $134.49 205 3.4 25 BULK-ab7c2e55
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