Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

899 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 899 Results Showing 22451 - 22475 of 24441

ID Name Category Price Stock Rating Reviews SKU
23010 Bulk Product b9f0c648 Electronics $318.86 416 1.5 22 BULK-47bcab62
23011 Bulk Product 08b8eb46 Books $420.49 248 3.0 51 BULK-647f1b55
23012 Bulk Product c978eee4 Books $597.56 489 4.3 1 BULK-bc2a9d32
23013 Bulk Product f81dcc36 Electronics $60.04 474 0.5 75 BULK-80b9a8a9
23014 Bulk Product dfe54738 Electronics $133.55 85 1.0 94 BULK-5f91ad57
23015 Bulk Product 1da9af08 Electronics $138.14 180 4.9 61 BULK-0bd0d471
23016 Bulk Product e4b0baa3 Toys & Games $12.36 175 1.8 62 BULK-dc8d2292
23017 Bulk Product abf20210 Clothing $732.26 438 4.7 26 BULK-8639666d
23018 Bulk Product db445af2 Home & Garden $967.79 165 3.3 17 BULK-9c7a4bf5
23019 Bulk Product dfe91e1d Home & Garden $734.81 213 3.3 85 BULK-8e26cca3
23020 Bulk Product 17e9b5d4 Books $705.90 205 5.0 78 BULK-f9c1d03a
23021 Bulk Product 279a9526 Home & Garden $129.19 375 4.3 81 BULK-b43ef217
23022 Bulk Product 7f6ddd44 Toys & Games $727.78 223 4.0 70 BULK-09dae538
23023 Bulk Product 047afea0 Books $273.63 140 1.4 71 BULK-d2c543b0
23024 Bulk Product 3db13b1f Clothing $721.88 443 3.2 12 BULK-5e9e18bd
23025 Bulk Product 89b1025a Books $41.17 56 3.2 22 BULK-6d74ab01
23026 Bulk Product 80478a6d Books $597.30 267 3.5 85 BULK-76902b64
23027 Bulk Product 33f36bed Books $1,000.88 18 2.8 0 BULK-07664b4e
23028 Bulk Product 183fb346 Clothing $378.46 279 1.9 94 BULK-59ccd5a7
23029 Bulk Product 43f6485b Clothing $293.46 87 4.1 43 BULK-4069cf37
23030 Bulk Product 59664404 Electronics $246.86 422 3.5 29 BULK-bf7b03b2
23031 Bulk Product 65c6d6bc Books $463.85 261 0.7 63 BULK-41db9aaf
23032 Bulk Product 2c10cca3 Books $170.55 486 1.9 60 BULK-2f47ba1a
23033 Bulk Product 8f829a52 Books $257.28 335 4.2 67 BULK-c5e14882
23034 Bulk Product e8069411 Sports & Outdoors $689.34 283 4.1 32 BULK-6bc65795
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