Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

41 ms

Page Size

25

Current Page

752 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 752 Results Showing 18776 - 18800 of 24441

ID Name Category Price Stock Rating Reviews SKU
19335 Bulk Product e99126b8 Sports & Outdoors $727.95 92 0.9 44 BULK-ea810a6a
19336 Bulk Product c8e975a1 Home & Garden $296.56 387 1.2 51 BULK-ba02fd88
19337 Bulk Product 7b215477 Sports & Outdoors $983.18 49 4.2 35 BULK-0847c84b
19338 Bulk Product 731f2bcc Electronics $752.67 158 5.0 57 BULK-3b54e1cc
19339 Bulk Product eac296dd Clothing $266.98 107 4.5 6 BULK-95cd3072
19340 Bulk Product 1031b69c Sports & Outdoors $846.20 414 2.6 48 BULK-d8bdd197
19341 Bulk Product 924b8871 Electronics $889.09 188 2.1 82 BULK-bfaf0997
19342 Bulk Product 2f10bf25 Clothing $185.88 132 0.8 83 BULK-e7c6fc05
19343 Bulk Product 45682556 Books $351.67 400 4.1 98 BULK-703f007b
19344 Bulk Product b8aedc84 Books $854.97 294 3.5 79 BULK-74fd7126
19345 Bulk Product acb25af9 Toys & Games $352.96 124 3.6 0 BULK-b57513aa
19346 Bulk Product 657ebab0 Toys & Games $719.94 59 3.4 0 BULK-c9260012
19347 Bulk Product 0617fbd3 Clothing $911.04 493 4.9 33 BULK-5420bbb5
19348 Bulk Product 845b3b6f Sports & Outdoors $341.45 396 0.3 10 BULK-08b74176
19349 Bulk Product 9e0dccba Electronics $101.47 44 4.9 62 BULK-fc153e8f
19350 Bulk Product a7895795 Toys & Games $881.81 100 2.1 90 BULK-de33558f
19351 Bulk Product 26093258 Electronics $634.89 145 3.5 13 BULK-5ff7cfa0
19352 Bulk Product 6c2d98d1 Books $745.57 164 3.3 73 BULK-fc44d578
19353 Bulk Product c4313c82 Electronics $927.41 157 1.8 56 BULK-fb558958
19354 Bulk Product cde8d0c8 Electronics $875.30 269 3.8 33 BULK-ac072423
19355 Bulk Product ecde3585 Home & Garden $816.20 25 1.5 76 BULK-20cdf4e0
19356 Bulk Product fdf8e536 Toys & Games $569.05 36 2.6 22 BULK-9a5574e3
19357 Bulk Product 44249a34 Home & Garden $750.73 39 2.5 88 BULK-9cc0f623
19358 Bulk Product a4e99ebc Electronics $805.30 38 3.4 80 BULK-67e4ff4f
19359 Bulk Product 52da43e3 Clothing $659.47 464 3.9 4 BULK-853488fb
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