Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

46 ms

Page Size

25

Current Page

822 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 822 Results Showing 20526 - 20550 of 24441

ID Name Category Price Stock Rating Reviews SKU
21085 Bulk Product 863796d3 Electronics $311.57 14 4.0 20 BULK-93642fac
21086 Bulk Product 9aeb164e Toys & Games $513.36 368 2.4 36 BULK-b0278333
21087 Bulk Product f21ab940 Books $400.84 154 1.4 25 BULK-b8cc478b
21088 Bulk Product 8e99ace5 Electronics $411.10 288 0.8 55 BULK-ce021c83
21089 Bulk Product 11e0f0b8 Sports & Outdoors $451.14 415 1.2 42 BULK-9fbb3820
21090 Bulk Product 734df07c Clothing $872.56 101 3.7 24 BULK-9d033c25
21091 Bulk Product eccda0aa Electronics $191.21 39 2.0 80 BULK-31076e80
21092 Bulk Product b83d9c91 Books $833.15 478 2.5 55 BULK-cc562aac
21093 Bulk Product c9ddfe2b Electronics $246.38 128 0.1 44 BULK-0784586c
21094 Bulk Product 2b612147 Electronics $801.00 393 0.4 71 BULK-99e33e98
21095 Bulk Product 0846b78b Home & Garden $292.15 2 0.6 81 BULK-cbb6f9ec
21096 Bulk Product 4667a489 Clothing $859.05 183 3.0 12 BULK-b3d4c9bd
21097 Bulk Product 2dc07984 Books $64.28 338 1.3 97 BULK-3bb3050e
21098 Bulk Product 26be3e18 Sports & Outdoors $620.24 169 2.6 92 BULK-08ffd8c7
21099 Bulk Product f47904ea Clothing $754.50 233 2.7 38 BULK-6b3099b0
21100 Bulk Product 8ebe918b Sports & Outdoors $123.81 488 4.3 84 BULK-fc255332
21101 Bulk Product 9e19a374 Sports & Outdoors $719.42 260 0.7 42 BULK-4464c816
21102 Bulk Product 5c4739f6 Home & Garden $59.67 85 0.0 8 BULK-3e27931e
21103 Bulk Product 327324fd Home & Garden $420.46 95 4.2 86 BULK-641b87b0
21104 Bulk Product 8a32762e Clothing $1,002.62 454 1.5 56 BULK-e277befb
21105 Bulk Product b6c2dc68 Toys & Games $891.99 16 2.0 63 BULK-76bf9500
21106 Bulk Product 84f1ddff Electronics $508.76 241 4.0 81 BULK-e9addd26
21107 Bulk Product 1f8c8c93 Sports & Outdoors $660.10 277 0.2 13 BULK-c58fe79b
21108 Bulk Product cd39620a Home & Garden $426.05 424 3.9 43 BULK-00b088f4
21109 Bulk Product b14ccb85 Home & Garden $119.62 110 4.6 87 BULK-8249fe30
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