Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

178 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 178 Results Showing 4426 - 4450 of 24441

ID Name Category Price Stock Rating Reviews SKU
4983 Mega Automotive Product 2024 Automotive $256.11 473 4.8 338 SKU-004983
4984 Standard Clothing Product Max Clothing $794.18 291 3.3 474 SKU-004984
4985 Deluxe Health & Beauty Product Lite Health & Beauty $457.04 394 2.9 254 SKU-004985
4986 Deluxe Health & Beauty Product XL Health & Beauty $195.69 384 4.3 309 SKU-004986
4988 Premium Home & Garden Product Lite Home & Garden $747.57 152 3.6 996 SKU-004988
4989 Super Clothing Product Special Edition Clothing $397.58 219 3.2 76 SKU-004989
4990 Elite Home & Garden Product Max Home & Garden $164.57 472 4.4 748 SKU-004990
4991 Pro Clothing Product Max Clothing $747.23 413 4.0 547 SKU-004991
4992 Elite Toys & Games Product Mini Toys & Games $846.85 364 3.0 685 SKU-004992
4993 Economy Food & Grocery Product 2024 Food & Grocery $926.32 26 1.8 161 SKU-004993
4994 Elite Clothing Product XL Clothing $778.59 352 4.3 410 SKU-004994
4995 Economy Toys & Games Product Pro Toys & Games $306.07 6 4.4 797 SKU-004995
4997 Elite Home & Garden Product Advanced Home & Garden $89.35 383 2.2 476 SKU-004997
4998 Standard Automotive Product Mini Automotive $618.16 289 3.3 46 SKU-004998
4999 Economy Clothing Product 2024 Clothing $818.87 486 2.0 691 SKU-004999
5000 Super Clothing Product 2024 Clothing $795.44 93 1.5 350 SKU-005000
5001 Bulk Product 45ac2598 Toys & Games $809.37 149 2.5 97 BULK-638cf492
5002 Bulk Product 86c5c2e3 Toys & Games $59.60 193 0.9 64 BULK-a5a0235c
5003 Bulk Product 8dfb22ae Books $496.89 286 2.6 47 BULK-2c846444
5004 Bulk Product d6974228 Sports & Outdoors $997.50 461 3.3 58 BULK-70607953
5005 Bulk Product 748791d0 Home & Garden $574.00 98 0.6 30 BULK-50cc55e9
5006 Bulk Product 6ac5ae54 Books $612.99 157 1.4 85 BULK-7bad3a7c
5007 Bulk Product 9545d593 Books $95.51 339 0.4 63 BULK-352608e3
5008 Bulk Product f1d95d26 Clothing $160.61 144 3.6 9 BULK-9bffeda3
5009 Bulk Product 87e5902f Clothing $158.02 461 4.9 32 BULK-1e3d48b5
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