Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

24 ms

Page Size

25

Current Page

951 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 951 Results Showing 23751 - 23775 of 24441

ID Name Category Price Stock Rating Reviews SKU
24310 Bulk Product 6e79db2f Clothing $284.40 318 2.1 99 BULK-4642a785
24311 Bulk Product 740f0699 Clothing $328.23 14 2.3 40 BULK-9eac89ac
24312 Bulk Product a7990844 Home & Garden $663.43 33 4.9 9 BULK-521429e5
24313 Bulk Product bb10f485 Sports & Outdoors $686.33 41 2.0 89 BULK-f23d8c10
24314 Bulk Product ba5302cb Home & Garden $131.50 144 4.7 11 BULK-f53c335a
24315 Bulk Product fa21fad3 Toys & Games $98.62 494 2.6 50 BULK-5dd9eace
24316 Bulk Product f0048439 Toys & Games $375.39 132 3.4 75 BULK-0ce4b846
24317 Bulk Product 526f347a Toys & Games $813.07 213 1.6 14 BULK-2ead0834
24318 Bulk Product 85987399 Sports & Outdoors $925.51 350 3.7 51 BULK-241f1d73
24319 Bulk Product b1b43200 Clothing $827.67 220 0.5 60 BULK-641a1ed5
24320 Bulk Product dc65aeec Toys & Games $640.10 155 4.8 2 BULK-294743b9
24321 Bulk Product 920547fd Sports & Outdoors $895.06 26 0.3 95 BULK-150f235f
24322 Bulk Product b582bbf5 Home & Garden $285.81 481 2.6 51 BULK-37a94340
24323 Bulk Product 2bc3fc48 Sports & Outdoors $688.80 415 2.9 38 BULK-13b07785
24324 Bulk Product 162ac8c0 Books $359.49 348 0.1 98 BULK-c949d1fb
24325 Bulk Product ae6f9e07 Toys & Games $477.51 458 0.3 13 BULK-82aecc07
24326 Bulk Product 4bc1ae80 Toys & Games $220.96 418 3.8 19 BULK-5c829765
24327 Bulk Product f181a99d Home & Garden $607.30 387 3.1 4 BULK-9217aeb3
24328 Bulk Product 4adf57df Sports & Outdoors $737.91 237 1.5 4 BULK-f441a1e6
24329 Bulk Product 80bbe631 Clothing $82.58 408 2.3 93 BULK-6cbe755b
24330 Bulk Product 2aee29ae Electronics $686.90 219 2.2 21 BULK-1ca91e8d
24331 Bulk Product f64a0690 Home & Garden $403.92 488 4.6 79 BULK-a633427c
24332 Bulk Product a2e1fd56 Toys & Games $581.57 269 0.2 51 BULK-c21d565e
24333 Bulk Product 77e9f7a1 Clothing $43.92 447 2.2 37 BULK-9239b560
24334 Bulk Product 98238be7 Books $826.38 392 4.9 74 BULK-93b5d3ea
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