Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

44 ms

Page Size

25

Current Page

867 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 867 Results Showing 21651 - 21675 of 24441

ID Name Category Price Stock Rating Reviews SKU
22210 Bulk Product 58f0b3b1 Books $646.45 183 1.3 30 BULK-94d70932
22211 Bulk Product 25501754 Sports & Outdoors $835.89 140 2.1 43 BULK-aafeffa1
22212 Bulk Product 034632ed Sports & Outdoors $639.29 165 4.4 93 BULK-25c810c7
22213 Bulk Product 1a0ebbf5 Toys & Games $797.98 277 4.4 41 BULK-20394c1b
22214 Bulk Product 9b21e218 Books $49.34 411 4.2 80 BULK-54f8e329
22215 Bulk Product e2191e5a Electronics $593.40 140 2.3 17 BULK-16361ba8
22216 Bulk Product 7577a7bd Clothing $726.80 139 3.6 23 BULK-c207f53c
22217 Bulk Product 2af39035 Home & Garden $697.16 415 1.2 92 BULK-a25efde8
22218 Bulk Product 86f9c667 Clothing $996.37 370 1.0 51 BULK-98c86c48
22219 Bulk Product 2ccf84e3 Toys & Games $841.94 146 2.5 72 BULK-52bb8f6b
22220 Bulk Product 6ff64402 Toys & Games $378.66 182 4.6 70 BULK-fb4afc20
22221 Bulk Product 70390bbb Toys & Games $450.97 134 2.1 18 BULK-a9b6800a
22222 Bulk Product 25d1ef7f Books $674.47 127 0.2 47 BULK-f495e935
22223 Bulk Product c1daeb30 Home & Garden $410.91 493 4.2 81 BULK-d486c16b
22224 Bulk Product 2ef4820f Clothing $66.70 471 1.3 99 BULK-e996ad90
22225 Bulk Product 0880de70 Electronics $490.79 423 3.5 6 BULK-4e2339c6
22226 Bulk Product f2007658 Sports & Outdoors $146.94 59 3.0 75 BULK-0eca2806
22227 Bulk Product 1516265b Clothing $782.39 99 2.9 61 BULK-079eed60
22228 Bulk Product b1cfde23 Books $794.35 6 4.6 37 BULK-216dd5cf
22229 Bulk Product 943b41d6 Toys & Games $851.47 171 2.0 18 BULK-9b9e8901
22230 Bulk Product 49a19a2e Home & Garden $272.86 164 1.6 5 BULK-26bb0742
22231 Bulk Product 7952006d Clothing $694.55 225 4.5 96 BULK-fe0b76b2
22232 Bulk Product 2ed8d349 Clothing $659.48 296 1.6 45 BULK-cf85c144
22233 Bulk Product ecad890d Clothing $835.87 474 1.1 47 BULK-bbe07f00
22234 Bulk Product 1765f299 Toys & Games $83.30 385 3.9 86 BULK-efe777e4
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