Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

255 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 255 Results Showing 6351 - 6375 of 24441

ID Name Category Price Stock Rating Reviews SKU
6910 Bulk Product 26158e6c Clothing $774.63 335 3.2 73 BULK-2dc2ef3f
6911 Bulk Product b7c4775b Books $445.79 23 4.7 53 BULK-743f963a
6912 Bulk Product e9c67fab Clothing $981.41 172 0.8 2 BULK-efa03f0e
6913 Bulk Product 106d7464 Clothing $478.36 45 3.0 67 BULK-b4bb7b84
6914 Bulk Product 249df042 Home & Garden $686.88 191 2.7 30 BULK-3571b4be
6915 Bulk Product 96a7f7f4 Clothing $240.20 7 2.3 10 BULK-2ec26a49
6916 Bulk Product c2ed4c6c Toys & Games $492.43 61 0.5 19 BULK-f68753b2
6917 Bulk Product 7cc7fade Books $910.37 89 4.7 78 BULK-f6a001c4
6918 Bulk Product fe880078 Sports & Outdoors $177.76 86 2.1 31 BULK-253aea60
6919 Bulk Product 923b3eec Clothing $225.10 444 3.0 76 BULK-f4a7ebe5
6920 Bulk Product e37198b8 Clothing $284.66 274 1.8 46 BULK-2586bf11
6921 Bulk Product 532be370 Sports & Outdoors $854.53 320 1.7 63 BULK-949d24f8
6922 Bulk Product 18600889 Electronics $238.89 117 4.4 31 BULK-bdebf47a
6923 Bulk Product ff68e64e Electronics $881.82 462 2.4 61 BULK-b8166512
6924 Bulk Product 7bacb107 Clothing $475.85 134 0.6 38 BULK-ad411868
6925 Bulk Product c6195279 Clothing $904.70 74 1.6 10 BULK-6d74287f
6926 Bulk Product 4ebc1afe Electronics $155.06 207 1.3 25 BULK-de8cdb84
6927 Bulk Product 21cd0b45 Home & Garden $222.09 461 1.3 55 BULK-82add4d5
6928 Bulk Product 0428bc94 Home & Garden $582.97 68 1.7 57 BULK-78052b7e
6929 Bulk Product a7cc13bf Toys & Games $50.84 70 3.1 50 BULK-d9cc939a
6930 Bulk Product e822fbbf Books $748.58 64 0.3 36 BULK-84165a6a
6931 Bulk Product b4b71b7d Clothing $401.96 296 4.3 81 BULK-5d5a2350
6932 Bulk Product 22ba7bb3 Electronics $808.77 92 4.7 28 BULK-fb319150
6933 Bulk Product 3425c67a Clothing $272.53 450 4.0 61 BULK-288a8c1e
6934 Bulk Product 1a21145c Electronics $677.67 23 3.1 25 BULK-940a6c8f
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