Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

25

Current Page

439 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 439 Results Showing 10951 - 10975 of 24441

ID Name Category Price Stock Rating Reviews SKU
11510 Bulk Product 069b45c8 Electronics $532.16 23 1.9 19 BULK-56d1beee
11511 Bulk Product 38c65e32 Sports & Outdoors $582.86 138 4.9 84 BULK-93500f23
11512 Bulk Product 6521af50 Toys & Games $922.73 91 3.4 66 BULK-4df4564c
11513 Bulk Product 8e20fbcb Home & Garden $933.16 110 4.7 5 BULK-0cbe354c
11514 Bulk Product 99399f65 Electronics $635.99 7 1.0 70 BULK-dd0ba799
11515 Bulk Product 46120029 Electronics $985.83 453 5.0 33 BULK-cbe593c8
11516 Bulk Product bec4f0c0 Toys & Games $200.86 0 2.2 49 BULK-9ec61c14
11517 Bulk Product a5f0b66d Toys & Games $536.85 212 4.9 88 BULK-6e3b7704
11518 Bulk Product 361d4adf Home & Garden $208.62 197 1.9 52 BULK-a1c8885e
11519 Bulk Product 91eb3401 Home & Garden $547.20 52 0.8 46 BULK-de06e585
11520 Bulk Product a939e190 Sports & Outdoors $692.30 165 2.5 26 BULK-2084159f
11521 Bulk Product 0bc55013 Electronics $863.54 380 5.0 37 BULK-09bdc8f8
11522 Bulk Product f62f77bf Toys & Games $898.44 77 4.4 30 BULK-6f024735
11523 Bulk Product 6cbbc545 Home & Garden $60.13 382 3.8 36 BULK-412800e9
11524 Bulk Product 905eb8ac Books $777.19 146 0.0 42 BULK-b380b4c9
11525 Bulk Product 1bec6c69 Books $33.16 310 1.6 61 BULK-70b9bee6
11526 Bulk Product 36e344b3 Books $592.29 30 0.8 93 BULK-35181c3f
11527 Bulk Product f560e108 Home & Garden $257.75 486 3.0 34 BULK-9ccb94e8
11528 Bulk Product 6d0edd6b Toys & Games $73.11 493 4.7 22 BULK-86d625cc
11529 Bulk Product df4fe026 Toys & Games $825.38 4 4.5 93 BULK-b612160c
11530 Bulk Product dbf1b222 Sports & Outdoors $169.06 354 4.0 62 BULK-7a5dc9ee
11531 Bulk Product 6b7e19f9 Books $396.78 20 3.3 57 BULK-00c21052
11532 Bulk Product 6ee3dce4 Toys & Games $561.46 64 3.8 47 BULK-55119a76
11533 Bulk Product 406e1c4c Electronics $392.26 354 2.9 92 BULK-3f448be4
11534 Bulk Product 0a8fd0a5 Home & Garden $982.67 421 4.0 65 BULK-04fa3dff
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