Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

737 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 737 Results Showing 18401 - 18425 of 24441

ID Name Category Price Stock Rating Reviews SKU
18960 Bulk Product ac89cde3 Toys & Games $95.94 416 3.6 24 BULK-5176bc5d
18961 Bulk Product 9a06c842 Sports & Outdoors $462.79 374 4.7 63 BULK-4b317344
18962 Bulk Product 6886b4fd Toys & Games $390.12 307 4.2 93 BULK-07bccc1a
18963 Bulk Product 46bda540 Home & Garden $167.68 83 3.9 25 BULK-6a91eda3
18964 Bulk Product 7800e565 Clothing $100.34 92 3.2 29 BULK-957bad87
18965 Bulk Product 0f7a1759 Sports & Outdoors $988.44 400 3.4 83 BULK-7a61e761
18966 Bulk Product 6de7a4f8 Toys & Games $553.69 365 4.8 5 BULK-485c65a4
18967 Bulk Product bdfa6b63 Home & Garden $494.42 356 3.1 74 BULK-c6f86053
18968 Bulk Product e428a4ef Sports & Outdoors $421.84 76 0.1 51 BULK-9e10322a
18969 Bulk Product 671036c2 Clothing $103.48 282 0.9 12 BULK-1f7168a9
18970 Bulk Product 0c2e1a2a Electronics $121.58 106 0.4 36 BULK-8a260881
18971 Bulk Product ccb1e03b Toys & Games $919.04 143 4.7 3 BULK-a02d03be
18972 Bulk Product ea954345 Books $750.80 274 2.7 43 BULK-a0fcb9b2
18973 Bulk Product 35cb6fa4 Toys & Games $79.02 3 3.7 93 BULK-18085ac9
18974 Bulk Product ae7237ea Clothing $660.71 117 4.3 62 BULK-ccd1f826
18975 Bulk Product afebe42c Books $608.01 419 0.5 44 BULK-29d422b1
18976 Bulk Product 0999eac9 Toys & Games $242.22 314 4.8 50 BULK-10b2cff2
18977 Bulk Product 9a4fb799 Electronics $913.60 106 4.1 64 BULK-9a5ebea0
18978 Bulk Product 935dc1b3 Electronics $319.07 215 1.2 68 BULK-29e9feed
18979 Bulk Product 876c14cb Home & Garden $804.57 209 1.0 66 BULK-a4d7ff5b
18980 Bulk Product e09497d3 Electronics $18.45 214 1.6 52 BULK-e891e777
18981 Bulk Product 8386090a Books $511.85 451 3.3 82 BULK-9d40c17d
18982 Bulk Product fc60410e Home & Garden $759.16 237 0.2 60 BULK-73ced806
18983 Bulk Product 7b994d3d Home & Garden $545.99 18 2.0 31 BULK-282ca385
18984 Bulk Product 676a54e9 Books $59.90 495 3.0 61 BULK-c1b9c9ec
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