Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

105 ms

Page Size

25

Current Page

777 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 777 Results Showing 19401 - 19425 of 24441

ID Name Category Price Stock Rating Reviews SKU
19960 Bulk Product e572473d Home & Garden $471.91 48 0.6 48 BULK-21b29a0d
19961 Bulk Product 3760c5a4 Electronics $56.43 488 4.5 45 BULK-0f7156a2
19962 Bulk Product f64c67e2 Clothing $418.55 410 0.1 81 BULK-78f0240c
19963 Bulk Product aaf43dd1 Sports & Outdoors $817.24 166 3.6 97 BULK-185439dd
19964 Bulk Product 74b140f2 Clothing $205.21 489 3.5 59 BULK-fa6b7693
19965 Bulk Product a269ec06 Books $765.01 137 1.3 20 BULK-48d46322
19966 Bulk Product 262858ee Toys & Games $516.49 179 0.4 18 BULK-8294ddef
19967 Bulk Product d2805924 Clothing $40.92 34 0.2 1 BULK-83946c9e
19968 Bulk Product cb66eef1 Electronics $1,001.66 161 0.0 91 BULK-aef4e24c
19969 Bulk Product 00a139b0 Home & Garden $998.32 357 0.3 34 BULK-6b079f84
19970 Bulk Product 1c6d0671 Sports & Outdoors $208.96 217 0.3 78 BULK-4fd7f486
19971 Bulk Product 3ba25550 Toys & Games $859.04 416 0.8 22 BULK-b455d1c3
19972 Bulk Product 099731ac Toys & Games $186.14 328 4.1 97 BULK-971be1be
19973 Bulk Product 296ef73e Electronics $875.69 443 3.3 96 BULK-46d5a6b9
19974 Bulk Product c2eef546 Sports & Outdoors $80.92 410 3.7 99 BULK-ab755921
19975 Bulk Product 9437bfa4 Home & Garden $30.18 462 2.2 99 BULK-f9ce1798
19976 Bulk Product 60c0196f Electronics $532.99 261 0.9 82 BULK-fe7b898d
19977 Bulk Product f246d4ae Electronics $756.42 389 2.0 50 BULK-86a09252
19978 Bulk Product 3b847f1a Home & Garden $644.31 329 0.8 88 BULK-abfc0ff2
19979 Bulk Product 2393a121 Home & Garden $687.83 380 4.5 67 BULK-3358a191
19980 Bulk Product ebacfdb1 Sports & Outdoors $975.96 397 1.0 49 BULK-dce7f3f9
19981 Bulk Product 2710c744 Sports & Outdoors $759.98 427 0.9 28 BULK-196910cd
19982 Bulk Product 15fe9b21 Toys & Games $957.31 303 2.2 96 BULK-33063527
19983 Bulk Product b5a3e30f Sports & Outdoors $957.76 68 0.2 13 BULK-c6f2330d
19984 Bulk Product db909862 Electronics $783.40 362 1.0 9 BULK-67af2117
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