Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

25 ms

Page Size

25

Current Page

243 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 243 Results Showing 6051 - 6075 of 24441

ID Name Category Price Stock Rating Reviews SKU
6610 Bulk Product b19dd374 Electronics $354.37 376 0.6 35 BULK-7b96abdb
6611 Bulk Product d310b4b9 Home & Garden $794.76 396 4.4 41 BULK-077e63a9
6612 Bulk Product e8ad293e Clothing $125.09 90 3.1 32 BULK-53ce04ee
6613 Bulk Product 9edb15c7 Books $582.76 124 2.6 34 BULK-f38cb7f5
6614 Bulk Product fb419ca9 Sports & Outdoors $671.28 277 1.5 68 BULK-a3eefa5b
6615 Bulk Product 8d9500b4 Home & Garden $734.44 437 2.0 19 BULK-26e38225
6616 Bulk Product e6f3b6e2 Sports & Outdoors $386.01 261 2.3 29 BULK-5aa58810
6617 Bulk Product 4fc1aab3 Clothing $45.65 300 3.4 94 BULK-7a495332
6618 Bulk Product 090b3e5c Clothing $255.74 467 4.9 74 BULK-bc40b47b
6619 Bulk Product 81f9b5d5 Toys & Games $88.43 119 1.3 61 BULK-e935a4b6
6620 Bulk Product 8b7c1860 Toys & Games $356.65 76 4.9 14 BULK-a06495c4
6621 Bulk Product 852777c6 Toys & Games $705.27 104 1.3 50 BULK-af431c93
6622 Bulk Product 2a564f34 Sports & Outdoors $720.86 127 2.5 71 BULK-531fda06
6623 Bulk Product 5c546990 Toys & Games $10.23 197 4.7 53 BULK-e821f0c5
6624 Bulk Product acb4caa6 Books $908.67 497 2.4 59 BULK-d09bed53
6625 Bulk Product cfa70b9e Sports & Outdoors $214.36 50 4.7 54 BULK-1d9d4684
6626 Bulk Product 106288ee Books $528.40 240 1.8 7 BULK-4adbf6ea
6627 Bulk Product 5d113dd3 Home & Garden $759.60 423 4.9 97 BULK-5357f334
6628 Bulk Product 8713dc75 Electronics $501.97 5 3.3 98 BULK-af5072fb
6629 Bulk Product d729fb74 Home & Garden $958.50 290 2.7 89 BULK-f0b9bd6c
6630 Bulk Product c2ae1511 Clothing $608.76 193 1.1 32 BULK-6b8852cf
6631 Bulk Product 2328fd33 Home & Garden $822.86 17 5.0 54 BULK-c7c571c2
6632 Bulk Product 5e8b9a43 Sports & Outdoors $836.62 78 1.2 61 BULK-065568fe
6633 Bulk Product 1c10221e Toys & Games $820.19 224 1.7 1 BULK-75d97421
6634 Bulk Product 0635339a Home & Garden $860.56 128 4.0 58 BULK-dbea8200
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