Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

44 ms

Page Size

25

Current Page

758 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 758 Results Showing 18926 - 18950 of 24441

ID Name Category Price Stock Rating Reviews SKU
19485 Bulk Product 557ebf9f Electronics $573.84 256 0.5 79 BULK-2ac572ca
19486 Bulk Product ab1c40ef Clothing $280.39 254 3.3 5 BULK-57e27ad7
19487 Bulk Product 0868815a Electronics $914.38 112 2.2 85 BULK-35622601
19488 Bulk Product 3cce2d87 Home & Garden $737.04 444 1.5 32 BULK-c0c1ac2e
19489 Bulk Product 8e852dfc Home & Garden $611.59 53 0.6 9 BULK-41230359
19490 Bulk Product a29f1fd7 Books $207.34 112 3.2 78 BULK-536dad7c
19491 Bulk Product 4124a245 Clothing $609.58 410 2.9 47 BULK-316eb959
19492 Bulk Product a339d80f Toys & Games $958.29 263 3.3 89 BULK-cf15d600
19493 Bulk Product 69380f01 Clothing $636.30 216 0.8 6 BULK-c4200d2a
19494 Bulk Product 0085aaff Toys & Games $893.24 348 1.2 16 BULK-f1e83fb9
19495 Bulk Product 2089d2a7 Toys & Games $991.07 137 1.2 61 BULK-98697f60
19496 Bulk Product 1eaddc77 Books $700.21 308 4.5 25 BULK-44088d1a
19497 Bulk Product 8d5d6fc9 Toys & Games $933.73 331 3.4 53 BULK-d79ef208
19498 Bulk Product f2c53af3 Books $58.01 285 1.3 1 BULK-f1ee14d9
19499 Bulk Product af481df4 Sports & Outdoors $859.19 215 3.1 98 BULK-afbe61b0
19500 Bulk Product 29826d8d Books $155.80 274 0.9 93 BULK-394e444b
19501 Bulk Product 88458a71 Books $268.54 436 3.6 52 BULK-4a11e781
19502 Bulk Product b3af5a57 Clothing $143.26 449 2.4 92 BULK-f9e1a82f
19503 Bulk Product 545f61dc Toys & Games $804.30 437 0.3 0 BULK-b3b8c5e9
19504 Bulk Product 9bcf160f Home & Garden $549.98 334 2.1 51 BULK-ab344637
19505 Bulk Product e515311a Toys & Games $469.12 319 1.9 89 BULK-35597c6a
19506 Bulk Product 66d9afbe Sports & Outdoors $56.30 41 2.9 39 BULK-5830b1d1
19507 Bulk Product 82de6f24 Clothing $904.50 455 1.2 72 BULK-19647c5a
19508 Bulk Product 8ca39b43 Clothing $561.70 326 4.8 82 BULK-52c34185
19509 Bulk Product 00adb751 Sports & Outdoors $67.56 251 0.1 52 BULK-daaad03b
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