Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

277 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 277 Results Showing 6901 - 6925 of 24441

ID Name Category Price Stock Rating Reviews SKU
7460 Bulk Product feeca624 Toys & Games $962.79 411 4.6 48 BULK-13aa1f60
7461 Bulk Product c8548b2e Electronics $622.12 261 4.0 69 BULK-a77ca1c5
7462 Bulk Product 8de29b71 Sports & Outdoors $486.71 173 3.9 63 BULK-e55fdfae
7463 Bulk Product 38c54efb Electronics $175.79 212 4.5 77 BULK-27bd4c4d
7464 Bulk Product bc8d7029 Electronics $361.02 495 4.0 13 BULK-30295ca5
7465 Bulk Product e4e39b99 Electronics $312.96 493 1.7 60 BULK-1159b57a
7466 Bulk Product 5ab60127 Home & Garden $627.00 246 1.9 27 BULK-9bd03661
7467 Bulk Product e49d7cf0 Home & Garden $304.79 373 0.1 62 BULK-2c8e0959
7468 Bulk Product c22496f4 Electronics $862.41 226 0.3 58 BULK-1006ec93
7469 Bulk Product 524c850b Sports & Outdoors $940.87 453 3.0 60 BULK-580479a5
7470 Bulk Product b79b772c Toys & Games $409.49 323 4.9 22 BULK-c31afad3
7471 Bulk Product 807e20c9 Toys & Games $198.98 218 3.2 76 BULK-958cb9a5
7472 Bulk Product db4bf8e8 Clothing $528.94 215 1.7 39 BULK-0429c9b0
7473 Bulk Product 881cccc2 Toys & Games $217.19 206 3.5 14 BULK-8bd95c6a
7474 Bulk Product 48d42fbb Books $462.11 30 2.6 85 BULK-cbaeabd6
7475 Bulk Product 7c3138e6 Clothing $195.35 272 0.4 21 BULK-3b4b0def
7476 Bulk Product 033c9ae6 Sports & Outdoors $274.24 243 2.3 57 BULK-134a2842
7477 Bulk Product 7d916df5 Clothing $660.40 329 4.1 11 BULK-5859e284
7478 Bulk Product 7e0104f2 Toys & Games $301.70 343 0.2 42 BULK-25fa2fde
7479 Bulk Product 6d177d6f Electronics $190.33 378 0.1 90 BULK-4aebe6e6
7480 Bulk Product 5670cef8 Clothing $953.37 36 1.6 33 BULK-bd34bff1
7481 Bulk Product 01f89096 Toys & Games $57.21 5 4.7 77 BULK-f12e57ba
7482 Bulk Product 43133925 Electronics $226.32 461 0.6 68 BULK-b38a07c5
7483 Bulk Product 21661184 Electronics $676.59 196 3.4 43 BULK-6323add4
7484 Bulk Product 3b7eec45 Sports & Outdoors $47.87 402 1.5 13 BULK-6999f27e
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