Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

41 ms

Page Size

25

Current Page

875 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 875 Results Showing 21851 - 21875 of 24441

ID Name Category Price Stock Rating Reviews SKU
22410 Bulk Product 8abc793a Toys & Games $869.63 294 1.3 69 BULK-5c8c4123
22411 Bulk Product dc6474e6 Clothing $129.52 340 3.0 34 BULK-c4632216
22412 Bulk Product ae1db6a6 Toys & Games $773.58 269 0.8 82 BULK-783d01b4
22413 Bulk Product 725bdfb8 Toys & Games $423.56 129 3.4 31 BULK-8f7957b4
22414 Bulk Product 6bd89398 Electronics $997.26 343 4.2 79 BULK-a4ff986e
22415 Bulk Product aabebba9 Toys & Games $682.14 495 2.8 47 BULK-e669d3b0
22416 Bulk Product 6313b5b0 Home & Garden $90.76 310 0.1 32 BULK-7dc866dc
22417 Bulk Product 951a7db0 Toys & Games $950.62 259 1.6 52 BULK-72633642
22418 Bulk Product 41bcfd6b Clothing $268.13 332 4.7 67 BULK-f40a7efd
22419 Bulk Product ff3f1565 Sports & Outdoors $588.47 408 2.1 92 BULK-f1a5219d
22420 Bulk Product 63d9ba56 Sports & Outdoors $914.91 227 2.3 4 BULK-270f074a
22421 Bulk Product cfae2024 Toys & Games $17.66 72 3.9 70 BULK-df18810f
22422 Bulk Product 73f75b0a Sports & Outdoors $422.33 284 4.5 72 BULK-28fa22fe
22423 Bulk Product d138afa5 Electronics $58.33 249 4.1 50 BULK-f6e8c909
22424 Bulk Product 00651363 Books $658.68 319 0.7 16 BULK-f479c442
22425 Bulk Product a43f80d3 Books $576.61 246 3.6 85 BULK-b978d985
22426 Bulk Product 43a9af24 Electronics $279.30 432 4.2 15 BULK-86454401
22427 Bulk Product 43a3a5ee Electronics $951.47 176 2.3 64 BULK-4eaaea17
22428 Bulk Product ad9d81bd Sports & Outdoors $881.84 146 0.1 64 BULK-53335e4e
22429 Bulk Product 96035624 Clothing $213.72 387 1.8 62 BULK-47a94a17
22430 Bulk Product 91a3fe26 Electronics $275.52 67 2.8 21 BULK-7f1e87d2
22431 Bulk Product cb314e2d Books $895.58 383 1.0 7 BULK-2f555f7f
22432 Bulk Product 45844c4a Sports & Outdoors $406.35 187 1.9 52 BULK-5b215fec
22433 Bulk Product d4c01747 Clothing $758.15 174 2.4 45 BULK-325c5b30
22434 Bulk Product e4fd8a1d Home & Garden $176.30 140 2.8 15 BULK-4e16ad49
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