Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

32 ms

Page Size

25

Current Page

824 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 824 Results Showing 20576 - 20600 of 24441

ID Name Category Price Stock Rating Reviews SKU
21135 Bulk Product 6fcdf91d Home & Garden $726.45 406 1.0 14 BULK-bf897af6
21136 Bulk Product e6a6bd79 Electronics $36.66 484 1.7 8 BULK-6e1406dc
21137 Bulk Product 52b602ce Home & Garden $709.51 58 1.6 12 BULK-6eb7e363
21138 Bulk Product 74ac7887 Books $65.28 108 1.7 54 BULK-1a6e38c8
21139 Bulk Product 0e741e88 Sports & Outdoors $936.36 17 2.7 35 BULK-de683f5c
21140 Bulk Product a27e2d67 Electronics $307.57 291 0.8 17 BULK-fd6ba1f6
21141 Bulk Product 70e78101 Home & Garden $784.91 388 3.2 89 BULK-db3c2329
21142 Bulk Product 7a3c8059 Toys & Games $375.34 419 3.0 31 BULK-c53d914d
21143 Bulk Product e3fba2a1 Home & Garden $620.08 185 1.5 73 BULK-befddbc2
21144 Bulk Product a7fed5b0 Home & Garden $344.64 336 2.0 2 BULK-6ad9abbf
21145 Bulk Product 05efaa81 Sports & Outdoors $609.20 1 3.6 8 BULK-fdf365a8
21146 Bulk Product 0211a18f Home & Garden $720.35 486 0.6 78 BULK-d125f5b0
21147 Bulk Product 527aeae9 Toys & Games $588.63 492 0.9 39 BULK-965b5ce5
21148 Bulk Product f649a2c9 Books $776.76 440 2.7 23 BULK-e786f94c
21149 Bulk Product f40de9e0 Toys & Games $917.34 183 4.4 99 BULK-1f98c72a
21150 Bulk Product 6520bbcf Books $708.82 484 3.1 77 BULK-25dc6097
21151 Bulk Product eea95258 Sports & Outdoors $301.00 141 1.3 13 BULK-74e6f160
21152 Bulk Product 408a57e0 Sports & Outdoors $608.34 331 2.9 41 BULK-f27991c0
21153 Bulk Product c2374298 Clothing $524.76 120 2.6 17 BULK-fb2e1d32
21154 Bulk Product 703777a8 Books $938.35 162 4.8 41 BULK-271e3f45
21155 Bulk Product ee57a63b Sports & Outdoors $798.09 47 4.6 27 BULK-9e7f58aa
21156 Bulk Product d1cd15fa Electronics $869.48 123 3.6 34 BULK-22479043
21157 Bulk Product 83fc02a3 Home & Garden $831.85 399 2.8 60 BULK-871b8f9e
21158 Bulk Product 52c32165 Sports & Outdoors $350.62 135 0.8 9 BULK-13ea4c47
21159 Bulk Product 319d968f Clothing $94.73 100 3.0 27 BULK-f3b777cd
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