Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

22 ms

Page Size

25

Current Page

619 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 619 Results Showing 15451 - 15475 of 24441

ID Name Category Price Stock Rating Reviews SKU
16010 Bulk Product f04181c0 Toys & Games $289.79 244 3.9 97 BULK-f11fa396
16011 Bulk Product 18ef9749 Sports & Outdoors $677.21 256 1.0 61 BULK-b102c25e
16012 Bulk Product 8995772a Clothing $634.97 118 2.4 45 BULK-0654b35a
16013 Bulk Product b98fe0de Sports & Outdoors $815.67 472 4.5 66 BULK-f5e63bc2
16014 Bulk Product 9d98c6b8 Books $639.72 370 2.9 13 BULK-77e00617
16015 Bulk Product 5abcd128 Electronics $925.75 315 0.8 99 BULK-59d08f8a
16016 Bulk Product 0c04f336 Sports & Outdoors $649.92 160 4.1 62 BULK-fe861d34
16017 Bulk Product abd430cc Home & Garden $243.49 107 1.5 90 BULK-84ce2b1b
16018 Bulk Product 8720f2b0 Clothing $148.58 319 3.0 6 BULK-b9202fd0
16019 Bulk Product f9438948 Sports & Outdoors $464.38 455 3.9 51 BULK-5442d32a
16020 Bulk Product 7a730605 Clothing $410.54 68 2.8 77 BULK-e9571a54
16021 Bulk Product 0c6bdeee Clothing $941.92 466 2.0 57 BULK-60964e56
16022 Bulk Product 97641871 Sports & Outdoors $943.48 257 4.7 7 BULK-fcaacc9e
16023 Bulk Product 83e6cda0 Clothing $94.24 146 2.5 14 BULK-ecc80aad
16024 Bulk Product ce533114 Clothing $209.25 453 2.0 65 BULK-25e57402
16025 Bulk Product 24bf71fd Home & Garden $67.42 371 0.4 99 BULK-f8d8aad6
16026 Bulk Product 9eece08e Electronics $80.50 329 4.8 80 BULK-0057674f
16027 Bulk Product e32908d5 Sports & Outdoors $733.60 292 4.8 43 BULK-61bb8a7e
16028 Bulk Product ece0605e Clothing $330.16 425 0.7 72 BULK-6489ee36
16029 Bulk Product b6bb0355 Books $67.29 325 1.7 45 BULK-6ba955a1
16030 Bulk Product d645accd Home & Garden $941.79 444 4.2 98 BULK-18729e47
16031 Bulk Product 21e0b2e6 Toys & Games $860.24 165 3.3 89 BULK-bdc00e5b
16032 Bulk Product 72fd19fb Electronics $932.05 340 2.3 92 BULK-80396fdf
16033 Bulk Product f2a59a1b Toys & Games $358.55 281 2.3 16 BULK-a16bfef9
16034 Bulk Product f61b1b87 Home & Garden $673.54 466 0.6 51 BULK-0da31481
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