Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

25

Current Page

557 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 557 Results Showing 13901 - 13925 of 24441

ID Name Category Price Stock Rating Reviews SKU
14460 Bulk Product b9ed3fbb Home & Garden $483.20 193 4.5 55 BULK-2d6e1809
14461 Bulk Product 04857447 Sports & Outdoors $717.86 206 3.0 99 BULK-8dd7c90e
14462 Bulk Product 8e81b0e9 Clothing $104.07 54 1.5 46 BULK-513888fd
14463 Bulk Product 476e1ed2 Clothing $39.52 454 4.8 61 BULK-f1a42945
14464 Bulk Product 0f384804 Home & Garden $303.71 452 4.6 26 BULK-07dfa740
14465 Bulk Product ae9b49a7 Books $488.17 227 2.4 59 BULK-d8bc0952
14466 Bulk Product f4ae53e8 Clothing $960.99 407 4.3 71 BULK-5b927ac2
14467 Bulk Product 3a3e2608 Clothing $877.19 487 3.4 80 BULK-5a9d5571
14468 Bulk Product bf8305d8 Sports & Outdoors $981.32 111 4.7 60 BULK-ff18ec81
14469 Bulk Product 35d81528 Home & Garden $364.72 423 3.3 60 BULK-8e9cbfbb
14470 Bulk Product c48d95fd Electronics $634.03 461 1.6 83 BULK-ca778cbc
14471 Bulk Product 992684ba Sports & Outdoors $918.47 62 3.6 50 BULK-f12a471b
14472 Bulk Product 9ec75c50 Home & Garden $573.66 294 1.6 57 BULK-81c2371f
14473 Bulk Product 7324b986 Home & Garden $477.17 322 1.3 29 BULK-7b27a831
14474 Bulk Product 1e7eb7bc Sports & Outdoors $331.88 265 4.9 33 BULK-1656a7f5
14475 Bulk Product 29ddb1d4 Books $405.46 27 0.0 4 BULK-406cee33
14476 Bulk Product 55768e5b Clothing $885.02 34 1.4 4 BULK-f2f4b41a
14477 Bulk Product 31c1dadc Toys & Games $50.71 468 2.0 52 BULK-b1dfbe7c
14478 Bulk Product 3541ad7f Sports & Outdoors $907.59 151 2.8 10 BULK-fdcb1410
14479 Bulk Product aa3717ef Home & Garden $555.52 245 2.9 35 BULK-6e5b6990
14480 Bulk Product 7790a51f Home & Garden $232.50 460 3.5 61 BULK-37a0d54d
14481 Bulk Product 059bf8a0 Books $917.55 43 4.8 85 BULK-2b936fc5
14482 Bulk Product a5be0c49 Books $13.87 182 3.5 7 BULK-2d43b455
14483 Bulk Product c511d882 Toys & Games $857.57 20 0.8 56 BULK-f72dd974
14484 Bulk Product 3a1cbe51 Toys & Games $516.60 206 4.3 62 BULK-b05f7e8c
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