Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

657 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 657 Results Showing 16401 - 16425 of 24441

ID Name Category Price Stock Rating Reviews SKU
16960 Bulk Product 286442c7 Sports & Outdoors $528.61 488 2.8 92 BULK-77f83cb1
16961 Bulk Product 448c1cee Home & Garden $895.77 294 4.4 53 BULK-02f3af9d
16962 Bulk Product fd71b8d1 Sports & Outdoors $455.70 465 0.2 59 BULK-b4efcbf9
16963 Bulk Product b8c20390 Sports & Outdoors $562.23 321 3.9 79 BULK-c2d74a21
16964 Bulk Product 1ea151f5 Home & Garden $346.92 498 1.3 59 BULK-77364daa
16965 Bulk Product 126cc0dd Books $662.59 352 4.7 8 BULK-7e3a392c
16966 Bulk Product 2dd9f35e Toys & Games $437.26 110 1.1 46 BULK-4f051feb
16967 Bulk Product 89332499 Sports & Outdoors $837.79 194 0.6 28 BULK-4f1afa11
16968 Bulk Product 79d18b6c Home & Garden $664.85 483 3.6 63 BULK-a3e41ccd
16969 Bulk Product bf7efb19 Toys & Games $368.51 81 0.3 99 BULK-5bc25ba8
16970 Bulk Product a43104c8 Sports & Outdoors $162.58 249 4.3 3 BULK-8cfc34d8
16971 Bulk Product d87f7d7b Sports & Outdoors $917.50 293 1.5 81 BULK-43d96686
16972 Bulk Product 4892b372 Sports & Outdoors $208.32 252 1.8 9 BULK-585b34bd
16973 Bulk Product 22f0cc39 Sports & Outdoors $573.49 461 3.1 14 BULK-cbe6719f
16974 Bulk Product abd854d6 Books $167.27 93 1.3 49 BULK-e0469ed1
16975 Bulk Product 6dcd827d Clothing $640.92 152 2.8 90 BULK-7383b4c7
16976 Bulk Product aec98ca7 Electronics $467.84 363 5.0 51 BULK-cc57172c
16977 Bulk Product e45723e4 Clothing $649.54 171 4.5 91 BULK-5f965f8d
16978 Bulk Product 6dbc8a3b Toys & Games $168.99 172 3.2 26 BULK-3fc187ce
16979 Bulk Product 9c6f5550 Electronics $565.10 80 0.7 74 BULK-a7ae6ef5
16980 Bulk Product a6f72d94 Home & Garden $369.79 206 1.4 47 BULK-5e88b5bb
16981 Bulk Product a4b757f4 Home & Garden $972.27 343 1.2 29 BULK-36a8703a
16982 Bulk Product 163fc4d8 Electronics $933.13 436 1.8 27 BULK-12a83638
16983 Bulk Product 56b0ddd1 Books $901.81 351 2.3 6 BULK-023cc835
16984 Bulk Product c959cb9a Books $312.85 301 4.4 88 BULK-b0e99226
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