Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

13 ms

Page Size

25

Current Page

502 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 502 Results Showing 12526 - 12550 of 24441

ID Name Category Price Stock Rating Reviews SKU
13085 Bulk Product a50b813e Sports & Outdoors $950.96 269 3.8 4 BULK-e46fbf46
13086 Bulk Product 90e74864 Home & Garden $996.43 280 1.9 50 BULK-43cbcfab
13087 Bulk Product e38988ec Toys & Games $994.35 446 0.5 56 BULK-9d75c28c
13088 Bulk Product b15fd89f Toys & Games $514.16 351 0.8 5 BULK-a04b70bd
13089 Bulk Product 590cd7f3 Clothing $980.11 347 2.9 67 BULK-3d81c3d6
13090 Bulk Product a999b055 Clothing $354.05 325 0.4 24 BULK-aef05e62
13091 Bulk Product ef9ab6cd Toys & Games $568.68 321 2.0 14 BULK-5015c699
13092 Bulk Product caee06d3 Home & Garden $961.87 59 1.8 73 BULK-898555ed
13093 Bulk Product cb81df54 Electronics $1,003.61 276 1.9 84 BULK-4737486b
13094 Bulk Product fe0bbe3a Electronics $127.38 195 1.4 4 BULK-93f87fd4
13095 Bulk Product edcbf941 Sports & Outdoors $338.39 490 1.4 92 BULK-fe2e3930
13096 Bulk Product da84af26 Home & Garden $412.78 342 3.7 27 BULK-8032d133
13097 Bulk Product 944dfcba Electronics $234.55 276 4.2 44 BULK-3b267432
13098 Bulk Product c918594c Books $147.10 9 2.6 86 BULK-d965121f
13099 Bulk Product 16095b2a Books $1,000.51 226 2.1 3 BULK-17b34e6c
13100 Bulk Product 5e1c3165 Electronics $750.77 112 4.2 3 BULK-c1f82df9
13101 Bulk Product bfed37a6 Toys & Games $42.92 491 2.6 49 BULK-b47ac71c
13102 Bulk Product 9ca20455 Books $176.68 397 2.5 4 BULK-65f736d6
13103 Bulk Product 1bd80052 Sports & Outdoors $111.51 389 4.9 27 BULK-45b46d96
13104 Bulk Product 14c98b32 Sports & Outdoors $633.40 374 1.2 47 BULK-c187785f
13105 Bulk Product 3e4c14d5 Clothing $814.86 458 3.7 79 BULK-1393b59d
13106 Bulk Product 0e7aa4cb Home & Garden $171.76 275 0.1 32 BULK-5052ff96
13107 Bulk Product 93c72be9 Toys & Games $489.08 94 3.8 5 BULK-b14166cb
13108 Bulk Product f91314a6 Sports & Outdoors $58.76 37 4.9 11 BULK-a935ac5f
13109 Bulk Product 6839b6dd Home & Garden $633.78 438 4.2 87 BULK-65d82858
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