Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

25

Current Page

343 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 343 Results Showing 8551 - 8575 of 24441

ID Name Category Price Stock Rating Reviews SKU
9110 Bulk Product 3e1bba8f Toys & Games $491.73 444 0.7 14 BULK-46d049ce
9111 Bulk Product 6b53c084 Books $972.56 470 0.3 57 BULK-5dbd3ed4
9112 Bulk Product 13b533d5 Books $313.52 146 1.1 36 BULK-40ab9fab
9113 Bulk Product a5e4fe63 Clothing $741.71 147 3.0 49 BULK-64874f15
9114 Bulk Product b162b08a Electronics $510.82 361 0.1 36 BULK-02bd1c1d
9115 Bulk Product 4b132759 Sports & Outdoors $546.64 238 3.3 51 BULK-dcff2663
9116 Bulk Product aa4a7189 Books $934.33 401 2.5 22 BULK-0e196d67
9117 Bulk Product 69002172 Home & Garden $268.39 152 2.2 60 BULK-ce855b3c
9118 Bulk Product 338e7fd6 Home & Garden $871.72 156 4.8 26 BULK-4acba67a
9119 Bulk Product 2ca12dae Home & Garden $805.08 248 1.1 11 BULK-34e83a81
9120 Bulk Product e5fd9d0b Books $198.60 341 3.1 92 BULK-8cba8682
9121 Bulk Product a63c35b3 Home & Garden $235.03 487 2.6 0 BULK-ba6497ed
9122 Bulk Product f3111dfa Clothing $127.67 287 1.3 96 BULK-2dcacc84
9123 Bulk Product 5cda7ce1 Toys & Games $219.79 66 4.3 80 BULK-5bb3584c
9124 Bulk Product 1215112d Electronics $381.10 145 4.8 3 BULK-60f20b89
9125 Bulk Product fbdeaf7e Clothing $151.97 168 3.3 10 BULK-c7ba32c9
9126 Bulk Product 2b9a991e Toys & Games $182.88 218 4.7 32 BULK-2e882631
9127 Bulk Product 89a5494d Clothing $929.26 315 2.7 15 BULK-9d49acb3
9128 Bulk Product 8d4be338 Electronics $480.56 389 4.1 19 BULK-aa8795ee
9129 Bulk Product b3cb7d84 Clothing $574.76 265 4.2 94 BULK-aa63812c
9130 Bulk Product 8ace15fc Electronics $824.29 95 3.9 26 BULK-10cacaed
9131 Bulk Product 2c3c03b6 Books $988.87 332 1.8 88 BULK-25704101
9132 Bulk Product 15793016 Clothing $452.57 102 1.1 11 BULK-ac30f20f
9133 Bulk Product ec95ca4c Clothing $418.01 397 2.6 85 BULK-35f68fd3
9134 Bulk Product e87d80d1 Electronics $926.07 86 2.7 28 BULK-ae025644
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