Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

65 ms

Page Size

25

Current Page

245 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 245 Results Showing 6101 - 6125 of 24441

ID Name Category Price Stock Rating Reviews SKU
6660 Bulk Product 4e3f59a9 Electronics $950.28 76 3.2 52 BULK-29ef197c
6661 Bulk Product d7afbc21 Books $385.64 401 4.4 7 BULK-555243ae
6662 Bulk Product 74501513 Home & Garden $106.21 433 3.3 9 BULK-086f82bc
6663 Bulk Product a5fb553a Home & Garden $902.20 154 3.3 91 BULK-8254dcad
6664 Bulk Product 9a6db99e Electronics $621.26 299 2.5 86 BULK-920f5858
6665 Bulk Product e59b582d Home & Garden $310.25 407 0.4 66 BULK-ae05936f
6666 Bulk Product 1c7a7047 Books $199.60 207 4.3 1 BULK-b061f309
6667 Bulk Product 7b384528 Toys & Games $365.94 341 2.3 90 BULK-59291464
6668 Bulk Product 15d1ca81 Clothing $154.14 115 3.9 9 BULK-5789665a
6669 Bulk Product 7e0da122 Books $53.70 365 1.9 70 BULK-78477a98
6670 Bulk Product f75a15da Books $120.53 378 0.1 88 BULK-ddf32767
6671 Bulk Product 1d70b2b3 Sports & Outdoors $737.16 39 4.8 77 BULK-a6a3f42f
6672 Bulk Product 3e5ecd53 Sports & Outdoors $394.36 380 4.4 73 BULK-e81e1184
6673 Bulk Product f09a54c2 Books $357.54 391 1.0 88 BULK-582d8707
6674 Bulk Product 597bc8c4 Electronics $333.14 238 3.3 10 BULK-903d33a7
6675 Bulk Product 73036205 Home & Garden $837.35 318 3.7 87 BULK-6ad03d9b
6676 Bulk Product 3d628aca Home & Garden $749.63 19 0.4 16 BULK-76b1da5c
6677 Bulk Product b98844d8 Sports & Outdoors $744.87 298 3.6 82 BULK-ef1e3dcd
6678 Bulk Product 0b675537 Toys & Games $143.32 252 0.2 16 BULK-dd1ad316
6679 Bulk Product b655077d Toys & Games $889.28 453 3.7 64 BULK-98cf289c
6680 Bulk Product cae6e8c1 Home & Garden $492.39 311 2.5 54 BULK-14be54cf
6681 Bulk Product 077628eb Electronics $624.67 255 1.0 67 BULK-18f48b5a
6682 Bulk Product f5f7ec32 Clothing $353.71 450 4.1 49 BULK-78d1bd2b
6683 Bulk Product 866a9d6a Clothing $614.68 185 4.4 5 BULK-6f897a9b
6684 Bulk Product 376d620d Books $496.41 172 0.0 4 BULK-19670f3d
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