Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

47 ms

Page Size

25

Current Page

83 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 83 Results Showing 2051 - 2075 of 24441

ID Name Category Price Stock Rating Reviews SKU
2306 Economy Home & Garden Product Special Edition Home & Garden $937.71 364 1.0 752 SKU-002306
2307 Ultra Home & Garden Product Max Home & Garden $691.15 164 4.0 923 SKU-002307
2308 Economy Clothing Product Mini Clothing $66.83 354 2.8 46 SKU-002308
2309 Ultra Sports & Outdoors Product 2024 Sports & Outdoors $421.90 80 1.7 9 SKU-002309
2310 Elite Sports & Outdoors Product Special Edition Sports & Outdoors $363.78 70 2.3 828 SKU-002310
2311 Economy Clothing Product Special Edition Clothing $261.52 147 4.5 22 SKU-002311
2312 Super Automotive Product Pro Automotive $198.32 274 2.4 729 SKU-002312
2313 Pro Health & Beauty Product 2024 Health & Beauty $801.29 83 1.1 356 SKU-002313
2314 Super Automotive Product Lite Automotive $346.86 117 2.7 681 SKU-002314
2316 Economy Food & Grocery Product XL Food & Grocery $552.98 43 2.3 583 SKU-002316
2318 Mega Books Product Pro Books $771.33 69 4.6 502 SKU-002318
2319 Economy Toys & Games Product Advanced Toys & Games $192.31 109 2.3 144 SKU-002319
2320 Premium Automotive Product Plus Automotive $50.84 360 3.1 313 SKU-002320
2321 Professional Sports & Outdoors Product Mini Sports & Outdoors $702.08 59 1.8 460 SKU-002321
2322 Elite Electronics Product XL Electronics $443.20 222 3.6 937 SKU-002322
2323 Ultra Health & Beauty Product Max Health & Beauty $36.29 12 2.7 771 SKU-002323
2324 Standard Office Supplies Product Lite Office Supplies $433.08 155 2.5 257 SKU-002324
2325 Deluxe Clothing Product 2024 Clothing $185.21 301 2.9 593 SKU-002325
2327 Super Electronics Product Mini Electronics $663.71 202 2.7 205 SKU-002327
2329 Super Automotive Product Advanced Automotive $157.96 456 4.5 443 SKU-002329
2330 Economy Toys & Games Product Plus Toys & Games $336.74 2 2.4 915 SKU-002330
2331 Deluxe Health & Beauty Product 2024 Health & Beauty $811.89 111 4.0 666 SKU-002331
2332 Economy Office Supplies Product Classic Office Supplies $341.19 197 1.6 45 SKU-002332
2334 Professional Office Supplies Product Advanced Office Supplies $572.94 179 2.1 582 SKU-002334
2336 Mega Sports & Outdoors Product Advanced Sports & Outdoors $138.20 113 3.5 945 SKU-002336
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