Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

25

Current Page

117 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 117 Results Showing 2901 - 2925 of 24441

ID Name Category Price Stock Rating Reviews SKU
3250 Pro Automotive Product Classic Automotive $226.30 183 1.7 940 SKU-003250
3251 Standard Food & Grocery Product Classic Food & Grocery $632.40 472 1.7 293 SKU-003251
3252 Economy Health & Beauty Product Lite Health & Beauty $757.26 253 1.5 85 SKU-003252
3253 Super Sports & Outdoors Product Mini Sports & Outdoors $534.55 208 2.4 174 SKU-003253
3254 Premium Sports & Outdoors Product Plus Sports & Outdoors $708.20 155 1.6 268 SKU-003254
3255 Pro Automotive Product Pro Automotive $689.89 481 3.4 236 SKU-003255
3256 Pro Electronics Product Mini Electronics $495.64 202 2.2 455 SKU-003256
3259 Super Electronics Product Plus Electronics $354.82 199 2.6 362 SKU-003259
3260 Premium Toys & Games Product Advanced Toys & Games $201.10 120 1.2 411 SKU-003260
3261 Standard Home & Garden Product Lite Home & Garden $448.70 355 1.7 384 SKU-003261
3262 Super Food & Grocery Product 2024 Food & Grocery $145.59 217 2.8 313 SKU-003262
3263 Economy Clothing Product Classic Clothing $649.92 267 2.8 754 SKU-003263
3264 Premium Food & Grocery Product Max Food & Grocery $557.48 195 3.0 528 SKU-003264
3267 Elite Books Product 2024 Books $378.82 361 1.7 845 SKU-003267
3268 Elite Electronics Product Advanced Electronics $124.68 61 4.3 954 SKU-003268
3269 Super Office Supplies Product Classic Office Supplies $541.41 134 1.2 179 SKU-003269
3270 Mega Home & Garden Product XL Home & Garden $18.00 306 4.1 760 SKU-003270
3271 Premium Clothing Product Mini Clothing $77.03 436 4.9 729 SKU-003271
3273 Professional Food & Grocery Product XL Food & Grocery $495.39 380 2.6 653 SKU-003273
3274 Professional Books Product Advanced Books $380.46 340 4.5 237 SKU-003274
3276 Elite Toys & Games Product XL Toys & Games $748.74 194 3.0 444 SKU-003276
3278 Professional Sports & Outdoors Product Max Sports & Outdoors $535.02 378 1.1 48 SKU-003278
3279 Professional Automotive Product 2024 Automotive $602.56 482 2.6 792 SKU-003279
3280 Standard Electronics Product Special Edition Electronics $387.11 204 3.8 248 SKU-003280
3281 Elite Sports & Outdoors Product XL Sports & Outdoors $294.55 209 3.5 201 SKU-003281
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