Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

24 ms

Page Size

25

Current Page

776 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 776 Results Showing 19376 - 19400 of 24441

ID Name Category Price Stock Rating Reviews SKU
19935 Bulk Product 4e309a40 Books $280.25 311 3.3 87 BULK-73c8d646
19936 Bulk Product 41be9769 Toys & Games $624.05 106 4.3 23 BULK-ddac535e
19937 Bulk Product 0681d2dd Books $255.08 31 0.1 38 BULK-9e463312
19938 Bulk Product 21313efa Sports & Outdoors $620.61 465 0.7 98 BULK-76a94d9c
19939 Bulk Product 3e8fbf9b Toys & Games $333.29 292 3.5 7 BULK-a397f91a
19940 Bulk Product 745cb988 Sports & Outdoors $204.13 338 1.1 76 BULK-ddf6c228
19941 Bulk Product 6c6e8237 Toys & Games $61.44 486 1.1 23 BULK-0d4b3985
19942 Bulk Product dd2c12a1 Clothing $898.80 46 4.1 33 BULK-b1f62e49
19943 Bulk Product c529e9e8 Sports & Outdoors $288.20 474 2.1 28 BULK-0bde4bb7
19944 Bulk Product f7f6e6e5 Home & Garden $237.07 168 2.8 64 BULK-795da64f
19945 Bulk Product df853c4a Books $569.99 124 1.2 17 BULK-ea49620e
19946 Bulk Product c4d22a62 Sports & Outdoors $388.54 120 0.9 88 BULK-fc58e184
19947 Bulk Product a1478c1c Home & Garden $117.87 379 2.6 6 BULK-8b7f4bd5
19948 Bulk Product d65925de Clothing $735.15 47 2.6 31 BULK-b1e1b149
19949 Bulk Product 65d3b055 Sports & Outdoors $309.99 496 2.2 28 BULK-078bb201
19950 Bulk Product 3301c4b0 Books $95.44 59 1.3 3 BULK-d0e8f5ce
19951 Bulk Product 59251112 Electronics $164.51 67 2.1 97 BULK-0453bb41
19952 Bulk Product b143d4a4 Toys & Games $745.85 66 0.0 11 BULK-e75814c1
19953 Bulk Product 063e0bbc Books $649.37 465 3.2 98 BULK-ad1f61c0
19954 Bulk Product 81447ffb Toys & Games $377.87 89 4.3 30 BULK-3a379ec1
19955 Bulk Product cfc40ff3 Toys & Games $241.81 32 2.0 72 BULK-912ad8e8
19956 Bulk Product 06e1c587 Clothing $486.64 408 2.2 10 BULK-2252e271
19957 Bulk Product 62799483 Toys & Games $771.83 420 4.8 44 BULK-c553e171
19958 Bulk Product c57d7258 Home & Garden $379.99 180 0.5 26 BULK-88ce00c2
19959 Bulk Product 7d01b02e Electronics $533.18 256 3.3 82 BULK-f1a3aaf3
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