Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

25

Current Page

414 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 414 Results Showing 10326 - 10350 of 24441

ID Name Category Price Stock Rating Reviews SKU
10885 Bulk Product 166182c5 Toys & Games $280.55 97 1.7 1 BULK-7bef77d9
10886 Bulk Product f5154d69 Electronics $169.83 454 2.1 47 BULK-1200d122
10887 Bulk Product 4b242dbe Electronics $316.81 401 1.3 86 BULK-2c2ba42e
10888 Bulk Product 77be996e Books $26.36 173 4.8 3 BULK-45c8acd0
10889 Bulk Product a7184c4a Home & Garden $256.83 48 2.3 18 BULK-f10a7c24
10890 Bulk Product 2137d4de Toys & Games $975.55 196 0.2 28 BULK-5f099cd2
10891 Bulk Product 049f2f13 Books $705.42 422 3.7 16 BULK-417becce
10892 Bulk Product e4700946 Books $982.05 193 4.2 95 BULK-ab877b91
10893 Bulk Product 24701881 Home & Garden $490.41 351 0.1 92 BULK-c9a7bbbd
10894 Bulk Product 13d427e7 Sports & Outdoors $910.97 235 2.1 58 BULK-c88b3152
10895 Bulk Product a7a8c268 Books $475.21 439 4.6 81 BULK-6f44a104
10896 Bulk Product f8f563b9 Sports & Outdoors $674.23 372 3.7 78 BULK-af5274e1
10897 Bulk Product 0a731b68 Electronics $523.74 97 4.8 18 BULK-933bd54f
10898 Bulk Product 512c65bb Clothing $831.85 154 2.9 91 BULK-157bc089
10899 Bulk Product a1396564 Toys & Games $366.46 393 2.3 26 BULK-4ead721f
10900 Bulk Product f7ecc6fa Toys & Games $716.50 363 2.8 64 BULK-fb394e11
10901 Bulk Product 9723cc55 Sports & Outdoors $307.64 52 4.0 31 BULK-392d353d
10902 Bulk Product c3ecdbc2 Home & Garden $408.94 486 4.3 14 BULK-0a105060
10903 Bulk Product c56e71b1 Toys & Games $106.00 379 1.4 36 BULK-fdf207f7
10904 Bulk Product 71f9af9e Home & Garden $889.52 10 4.8 57 BULK-348dbeb3
10905 Bulk Product d830a33e Books $439.69 375 2.7 14 BULK-460fce11
10906 Bulk Product 6b4d0be1 Clothing $176.42 23 2.7 13 BULK-924a4995
10907 Bulk Product b5ced554 Home & Garden $369.48 214 1.6 17 BULK-2ac66ac1
10908 Bulk Product a42f70de Electronics $340.17 483 0.7 74 BULK-e57d3adb
10909 Bulk Product f51d6468 Home & Garden $297.11 385 1.7 64 BULK-dd4fc0db
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