Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

374 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 374 Results Showing 9326 - 9350 of 24441

ID Name Category Price Stock Rating Reviews SKU
9885 Bulk Product f03114be Toys & Games $946.77 400 1.9 6 BULK-3f2636b9
9886 Bulk Product b9d46494 Clothing $180.48 370 4.5 61 BULK-35db9ac7
9887 Bulk Product e42d9526 Sports & Outdoors $150.85 84 4.0 35 BULK-592b46df
9888 Bulk Product 88db2500 Clothing $515.21 482 1.4 28 BULK-8c8ad77e
9889 Bulk Product bb7b2579 Home & Garden $21.01 127 2.5 51 BULK-67309c1e
9890 Bulk Product 826f2ef9 Electronics $292.05 138 1.7 57 BULK-7a4a4b4a
9891 Bulk Product 53085e9e Home & Garden $483.34 220 2.2 18 BULK-7259fd0d
9892 Bulk Product 3cc75d85 Home & Garden $831.07 132 0.4 87 BULK-05465af3
9893 Bulk Product 99189616 Books $942.28 67 4.7 91 BULK-a146b683
9894 Bulk Product c8158fbb Clothing $332.32 486 1.2 18 BULK-ffadcb5e
9895 Bulk Product f9263aa1 Home & Garden $900.34 251 3.4 63 BULK-ae4d159d
9896 Bulk Product 72fbc5c5 Clothing $670.61 402 3.5 85 BULK-caf38cdb
9897 Bulk Product 6a16e78b Home & Garden $139.35 485 1.3 21 BULK-8fd003f5
9898 Bulk Product 90eeb8e4 Books $299.25 362 0.6 73 BULK-218bd20f
9899 Bulk Product 51e8bb29 Toys & Games $971.67 420 0.5 33 BULK-7177a92c
9900 Bulk Product 17ba30ff Home & Garden $229.69 390 2.0 65 BULK-14f1105a
9901 Bulk Product 95d521e9 Clothing $124.30 345 4.6 26 BULK-9787d326
9902 Bulk Product a10bfe7b Home & Garden $862.89 86 1.2 86 BULK-a3e94056
9903 Bulk Product 72b9b0d0 Electronics $430.41 331 4.4 25 BULK-65961253
9904 Bulk Product b90dfe6e Clothing $59.73 444 0.1 46 BULK-e85cb9e1
9905 Bulk Product 7a9f8490 Books $844.41 311 3.6 65 BULK-d6fae526
9906 Bulk Product 715c2db0 Sports & Outdoors $704.28 288 4.7 12 BULK-79386bf1
9907 Bulk Product 55ca4a43 Toys & Games $470.38 245 0.9 32 BULK-e07c5b33
9908 Bulk Product ca784daa Toys & Games $255.66 466 4.7 93 BULK-6db9d7e2
9909 Bulk Product 47e3964a Sports & Outdoors $851.82 486 1.9 36 BULK-114de0a2
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