Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

32 ms

Page Size

25

Current Page

873 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 873 Results Showing 21801 - 21825 of 24441

ID Name Category Price Stock Rating Reviews SKU
22360 Bulk Product d7a48974 Electronics $806.94 417 3.4 13 BULK-311e2c03
22361 Bulk Product eba07d7c Home & Garden $715.50 373 1.9 26 BULK-e22a775a
22362 Bulk Product f7d292b7 Clothing $280.41 297 1.3 87 BULK-a669fb1e
22363 Bulk Product 8104b873 Sports & Outdoors $964.17 466 4.2 15 BULK-5e8b2572
22364 Bulk Product 2c4dc6d8 Sports & Outdoors $900.69 183 4.6 88 BULK-1cff2d26
22365 Bulk Product b084bd5e Toys & Games $770.50 454 1.8 24 BULK-25c11e10
22366 Bulk Product b60fa777 Home & Garden $179.05 93 0.2 6 BULK-2e816323
22367 Bulk Product e75be1e5 Toys & Games $247.69 377 4.7 95 BULK-18c4e8b8
22368 Bulk Product 3f5d7481 Electronics $114.64 264 4.0 15 BULK-a60c7fe9
22369 Bulk Product ced90a5d Clothing $498.92 467 1.1 87 BULK-dbe2fd74
22370 Bulk Product 3f11f047 Toys & Games $752.51 305 0.9 47 BULK-062a591f
22371 Bulk Product decc3821 Home & Garden $368.53 463 2.5 39 BULK-9e28dc3e
22372 Bulk Product d504c48f Sports & Outdoors $589.88 477 0.2 11 BULK-39f8f62e
22373 Bulk Product aa0b361e Home & Garden $257.48 220 1.6 65 BULK-71f72f86
22374 Bulk Product 9560d401 Home & Garden $321.38 59 2.9 19 BULK-a1a33785
22375 Bulk Product d6492bef Sports & Outdoors $707.71 318 3.3 83 BULK-13f30296
22376 Bulk Product e697f2fd Sports & Outdoors $785.27 400 4.5 68 BULK-ad7435ff
22377 Bulk Product 4367a8ef Toys & Games $714.59 23 1.3 58 BULK-49b45f8f
22378 Bulk Product 0efd998e Books $647.50 426 0.4 91 BULK-7140bfbc
22379 Bulk Product 7f9128db Home & Garden $940.66 33 1.0 54 BULK-a4ac4dda
22380 Bulk Product c55f514f Clothing $689.33 22 4.2 13 BULK-93a39511
22381 Bulk Product 0362916c Toys & Games $55.83 87 3.9 28 BULK-db346882
22382 Bulk Product a8d84bb8 Home & Garden $897.25 347 4.4 6 BULK-00180108
22383 Bulk Product 3d21c610 Home & Garden $166.04 155 2.3 31 BULK-eb733d3f
22384 Bulk Product 15e848e5 Sports & Outdoors $884.11 117 2.3 40 BULK-e107c991
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