Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

835 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 835 Results Showing 20851 - 20875 of 24441

ID Name Category Price Stock Rating Reviews SKU
21410 Bulk Product e79d62eb Clothing $232.74 394 3.2 10 BULK-92ae360d
21411 Bulk Product fb2c6763 Electronics $509.02 154 3.4 48 BULK-5cbaa72c
21412 Bulk Product 280ec1df Home & Garden $368.63 87 0.8 0 BULK-e7955330
21413 Bulk Product aa0963a0 Toys & Games $177.46 368 2.3 96 BULK-294f240a
21414 Bulk Product 5db7c200 Books $368.77 488 4.2 91 BULK-2043097c
21415 Bulk Product 1a4209c6 Home & Garden $279.68 106 2.4 71 BULK-1c462ef3
21416 Bulk Product 4d8e7a43 Electronics $54.99 421 3.3 16 BULK-c91b47c4
21417 Bulk Product 4a162059 Books $771.92 186 1.5 5 BULK-0dfe37c6
21418 Bulk Product f4d99bc1 Clothing $669.06 339 3.3 26 BULK-210777b3
21419 Bulk Product b5ea3848 Sports & Outdoors $322.38 208 2.8 78 BULK-5b13eb64
21420 Bulk Product e6c54414 Home & Garden $656.32 5 2.1 6 BULK-479de62c
21421 Bulk Product c42c807a Books $1,007.57 301 1.8 7 BULK-c73dc021
21422 Bulk Product 8c9d8ebd Sports & Outdoors $991.82 199 4.8 77 BULK-5f7bd1ec
21423 Bulk Product 500a0f5c Books $427.09 438 3.3 63 BULK-fa282f61
21424 Bulk Product fa611140 Electronics $489.85 341 0.7 55 BULK-cf7510a8
21425 Bulk Product 2510ac54 Electronics $781.11 9 2.4 27 BULK-c6fe6785
21426 Bulk Product 779839e5 Toys & Games $258.15 42 1.8 69 BULK-3f59dfe5
21427 Bulk Product 108034ba Toys & Games $62.64 421 1.8 33 BULK-a7227550
21428 Bulk Product bdad9da8 Clothing $669.08 111 1.1 80 BULK-e2360579
21429 Bulk Product 7e9ab257 Toys & Games $191.40 152 0.3 17 BULK-02641421
21430 Bulk Product 4c913a34 Sports & Outdoors $340.46 479 3.4 59 BULK-0ea46d21
21431 Bulk Product 8c17da97 Sports & Outdoors $55.68 117 0.1 95 BULK-da0a7371
21432 Bulk Product 1a8fdb1a Books $521.27 106 1.8 66 BULK-81a1921f
21433 Bulk Product 0a09f4eb Home & Garden $529.65 454 3.8 14 BULK-f249cb33
21434 Bulk Product 137bca73 Books $918.82 368 4.2 21 BULK-f5cb6627
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