Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

61 ms

Page Size

25

Current Page

273 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 273 Results Showing 6801 - 6825 of 24441

ID Name Category Price Stock Rating Reviews SKU
7360 Bulk Product f5c26a60 Home & Garden $212.79 198 2.9 36 BULK-f780b2e5
7361 Bulk Product bc441f36 Electronics $285.42 430 1.8 6 BULK-780016dc
7362 Bulk Product 22d81b53 Toys & Games $609.43 108 0.7 79 BULK-977a496d
7363 Bulk Product 1945e582 Books $879.09 115 2.3 4 BULK-9be08883
7364 Bulk Product ee6dd437 Electronics $888.74 465 4.5 46 BULK-369e3d49
7365 Bulk Product e6c2a01e Clothing $18.27 161 1.0 39 BULK-5df8ff2e
7366 Bulk Product d06cdda7 Books $234.80 101 3.3 64 BULK-e2f84869
7367 Bulk Product 60d95879 Home & Garden $686.36 494 1.5 91 BULK-e4693639
7368 Bulk Product c440fd43 Books $828.65 220 3.4 10 BULK-cb86a058
7369 Bulk Product c0fdd3aa Toys & Games $463.60 399 3.5 52 BULK-7fd1e6ef
7370 Bulk Product e5751e63 Sports & Outdoors $153.15 368 0.1 0 BULK-26aae8ee
7371 Bulk Product 9d623179 Toys & Games $531.28 380 0.5 38 BULK-ca6bd8cb
7372 Bulk Product ff90d42e Books $660.52 270 4.2 50 BULK-a3aa2fc6
7373 Bulk Product 61930f5f Home & Garden $703.03 351 4.0 10 BULK-59cbcab2
7374 Bulk Product ddf7da40 Books $808.09 411 2.7 79 BULK-8352e580
7375 Bulk Product 26d5a0a7 Clothing $790.45 377 0.4 80 BULK-687ab785
7376 Bulk Product a0d75239 Clothing $243.05 69 0.2 72 BULK-f839e2e4
7377 Bulk Product 0e813b92 Clothing $962.72 229 2.7 71 BULK-ba3c47d3
7378 Bulk Product 1dc848db Books $1,008.01 63 4.6 54 BULK-c30d8678
7379 Bulk Product c1e1e47c Sports & Outdoors $784.84 268 0.4 81 BULK-75bb7abe
7380 Bulk Product deea7d71 Clothing $843.34 461 4.2 45 BULK-d3bda497
7381 Bulk Product d9fb7937 Electronics $10.71 376 2.9 65 BULK-624016df
7382 Bulk Product b0800e22 Clothing $489.87 361 3.8 78 BULK-c373e9fb
7383 Bulk Product 04390931 Books $818.05 354 4.3 68 BULK-7d5ed404
7384 Bulk Product c84eff8d Home & Garden $262.67 29 4.8 17 BULK-1fa45faf
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