Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

25

Current Page

743 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 743 Results Showing 18551 - 18575 of 24441

ID Name Category Price Stock Rating Reviews SKU
19110 Bulk Product 15232dbe Books $505.70 56 1.8 63 BULK-dc152e5d
19111 Bulk Product b9396b34 Sports & Outdoors $678.62 285 1.6 7 BULK-aba2b33a
19112 Bulk Product 09fb2a75 Clothing $932.22 369 4.9 18 BULK-668bc36d
19113 Bulk Product 9807cdac Home & Garden $964.99 66 4.9 3 BULK-096cf5d5
19114 Bulk Product 1098f337 Home & Garden $776.56 33 1.2 87 BULK-2ed05499
19115 Bulk Product 84e22f9f Clothing $991.56 342 2.0 48 BULK-5c37ecb5
19116 Bulk Product 421bf413 Home & Garden $861.00 482 3.6 58 BULK-99b55ab6
19117 Bulk Product 479fcec1 Sports & Outdoors $660.99 242 2.0 40 BULK-cbc7128e
19118 Bulk Product b8351e27 Toys & Games $802.47 486 4.0 26 BULK-be2c0374
19119 Bulk Product 1cb42967 Books $467.13 326 2.6 3 BULK-338f1882
19120 Bulk Product 7300b4d8 Sports & Outdoors $559.32 225 4.2 53 BULK-b60d4df2
19121 Bulk Product c48c98df Sports & Outdoors $935.44 150 1.9 52 BULK-6afd369f
19122 Bulk Product 21c91965 Electronics $981.23 23 2.6 13 BULK-de7dd695
19123 Bulk Product 464c66c1 Clothing $802.56 206 3.5 54 BULK-f5c44151
19124 Bulk Product fa481667 Home & Garden $553.05 414 4.8 81 BULK-6f3ae7e7
19125 Bulk Product 86bd694f Books $836.62 324 1.7 35 BULK-a5c1057a
19126 Bulk Product 3cb036e9 Home & Garden $618.78 44 4.0 69 BULK-ed1361b4
19127 Bulk Product 9766081d Books $470.27 298 3.9 63 BULK-3428d534
19128 Bulk Product db8f3e35 Toys & Games $199.45 136 2.9 5 BULK-e15103d1
19129 Bulk Product be84c802 Sports & Outdoors $622.62 433 3.3 59 BULK-14049628
19130 Bulk Product e0326675 Clothing $906.80 127 3.2 48 BULK-40446e56
19131 Bulk Product 356e529f Clothing $37.38 186 2.1 27 BULK-5661f025
19132 Bulk Product cf618842 Books $426.09 416 2.3 30 BULK-008a07aa
19133 Bulk Product abf7b69a Toys & Games $591.38 251 1.6 52 BULK-070414e5
19134 Bulk Product fe718513 Clothing $821.77 193 2.2 42 BULK-ec8b5017
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