Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

34 ms

Page Size

25

Current Page

691 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 691 Results Showing 17251 - 17275 of 24441

ID Name Category Price Stock Rating Reviews SKU
17810 Bulk Product 5d5fe33e Sports & Outdoors $265.18 197 0.8 36 BULK-1fce3ee0
17811 Bulk Product 17129220 Toys & Games $919.36 15 3.4 41 BULK-89f1710c
17812 Bulk Product 9e958439 Clothing $33.96 442 2.7 26 BULK-157baacb
17813 Bulk Product e31eb435 Books $288.05 98 4.6 65 BULK-264d7bd1
17814 Bulk Product c6db853a Books $78.16 222 3.4 90 BULK-d9f26e4d
17815 Bulk Product 9bc5d2ec Electronics $222.10 174 0.7 70 BULK-f4a1da6f
17816 Bulk Product 997820f1 Books $207.39 481 0.7 72 BULK-664921e5
17817 Bulk Product df23d46c Electronics $764.29 361 1.4 62 BULK-7c069bce
17818 Bulk Product 022b3ea9 Clothing $589.49 284 1.7 33 BULK-50c858b0
17819 Bulk Product 9fba801c Clothing $865.77 496 3.5 56 BULK-0f92f123
17820 Bulk Product 593edc23 Books $338.53 288 0.0 93 BULK-bde5b058
17821 Bulk Product d91b7be2 Electronics $287.64 60 4.0 59 BULK-7000932e
17822 Bulk Product 795f9a38 Home & Garden $370.65 107 2.4 18 BULK-ef375a5e
17823 Bulk Product 24252430 Electronics $154.87 116 0.9 45 BULK-43f594c2
17824 Bulk Product 17720c2e Books $858.47 76 4.8 26 BULK-02a53e80
17825 Bulk Product d16fad68 Electronics $198.26 418 1.8 77 BULK-a3d687e8
17826 Bulk Product ecdcfe3c Books $986.55 269 2.5 72 BULK-c608ee35
17827 Bulk Product f9bc7aa1 Books $264.89 385 1.4 4 BULK-833f7ec9
17828 Bulk Product 1b11fbbf Toys & Games $735.72 156 1.2 7 BULK-9323f28f
17829 Bulk Product fe1dec8a Books $948.56 277 2.8 53 BULK-0df9e211
17830 Bulk Product 1df0261c Sports & Outdoors $719.22 378 1.8 39 BULK-ddb9c35e
17831 Bulk Product b62465f6 Toys & Games $1,008.09 28 0.4 2 BULK-638861b5
17832 Bulk Product 1d2ad240 Sports & Outdoors $612.64 185 0.2 22 BULK-03bdc82d
17833 Bulk Product fd50f6d6 Sports & Outdoors $636.01 92 2.4 62 BULK-0f78527d
17834 Bulk Product da63d8df Clothing $244.02 283 4.5 88 BULK-35a26931
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