Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

939 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 939 Results Showing 23451 - 23475 of 24441

ID Name Category Price Stock Rating Reviews SKU
24010 Bulk Product 297da5e4 Clothing $13.19 248 3.3 73 BULK-da7a0dbf
24011 Bulk Product da91c214 Sports & Outdoors $945.35 172 0.6 25 BULK-dceb084a
24012 Bulk Product f533c3a9 Sports & Outdoors $488.72 320 0.1 58 BULK-ffff4884
24013 Bulk Product c9795736 Toys & Games $605.08 130 4.6 72 BULK-7b453241
24014 Bulk Product b60fd60a Clothing $678.37 303 2.0 76 BULK-add9ac84
24015 Bulk Product 8bd6697b Sports & Outdoors $165.80 123 0.6 43 BULK-b598180e
24016 Bulk Product 28b78f2a Toys & Games $381.83 172 0.0 94 BULK-c0e3279a
24017 Bulk Product 0e8fab34 Clothing $982.05 431 1.6 88 BULK-1e9dc285
24018 Bulk Product 6451f776 Home & Garden $410.58 3 2.6 27 BULK-6d637404
24019 Bulk Product 6f0e30d0 Home & Garden $272.30 179 1.2 68 BULK-0d62a962
24020 Bulk Product 7c6e9fed Toys & Games $712.69 330 2.5 58 BULK-c99938ee
24021 Bulk Product a534d1f9 Books $78.36 192 4.7 97 BULK-f15d4c8a
24022 Bulk Product f7134913 Sports & Outdoors $608.89 22 3.0 23 BULK-e1c59434
24023 Bulk Product 53490b49 Sports & Outdoors $723.46 125 1.6 99 BULK-6018add3
24024 Bulk Product 2e216196 Toys & Games $621.35 44 4.6 65 BULK-7c8ec69f
24025 Bulk Product d0355f2e Sports & Outdoors $326.65 142 0.2 64 BULK-b5e5bc12
24026 Bulk Product cce9a0e9 Sports & Outdoors $651.00 130 1.9 57 BULK-18a508f3
24027 Bulk Product 7c33f47b Clothing $638.70 193 1.7 73 BULK-7242d53b
24028 Bulk Product 7e8e1127 Home & Garden $810.64 120 4.9 13 BULK-7bf5d3a5
24029 Bulk Product dfbaf768 Electronics $615.23 151 4.7 96 BULK-47b8284a
24030 Bulk Product 125c0999 Electronics $601.91 405 2.2 95 BULK-8d1a4c03
24031 Bulk Product b44a4414 Clothing $754.42 140 1.7 35 BULK-ca52f0cb
24032 Bulk Product 477fc0d9 Home & Garden $657.18 110 3.5 71 BULK-8a4c5686
24033 Bulk Product 05af5986 Sports & Outdoors $448.36 62 4.2 8 BULK-bfd08a24
24034 Bulk Product f95d7e32 Sports & Outdoors $511.60 265 4.9 23 BULK-5f872df7
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