Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

8 ms

Page Size

25

Current Page

48 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 48 Results Showing 1176 - 1200 of 24441

ID Name Category Price Stock Rating Reviews SKU
1330 Standard Health & Beauty Product Max Health & Beauty $481.45 438 4.7 199 SKU-001330
1332 Deluxe Sports & Outdoors Product Advanced Sports & Outdoors $698.91 3 2.6 692 SKU-001332
1333 Economy Food & Grocery Product Advanced Food & Grocery $341.32 204 3.7 639 SKU-001333
1334 Super Clothing Product Special Edition Clothing $217.64 49 4.4 392 SKU-001334
1335 Ultra Sports & Outdoors Product Mini Sports & Outdoors $642.01 298 1.1 807 SKU-001335
1336 Elite Clothing Product Max Clothing $815.53 191 2.9 73 SKU-001336
1337 Professional Books Product Pro Books $530.74 263 1.6 983 SKU-001337
1338 Mega Home & Garden Product Special Edition Home & Garden $718.30 163 2.5 368 SKU-001338
1339 Pro Office Supplies Product Pro Office Supplies $363.35 341 2.6 505 SKU-001339
1341 Standard Books Product Lite Books $192.45 240 3.5 478 SKU-001341
1342 Economy Automotive Product Special Edition Automotive $624.59 171 1.8 219 SKU-001342
1343 Ultra Toys & Games Product XL Toys & Games $704.58 479 2.0 574 SKU-001343
1344 Pro Home & Garden Product XL Home & Garden $865.44 169 5.0 634 SKU-001344
1345 Standard Clothing Product Pro Clothing $172.63 68 3.6 843 SKU-001345
1346 Ultra Food & Grocery Product Classic Food & Grocery $356.07 191 2.4 87 SKU-001346
1347 Ultra Toys & Games Product Advanced Toys & Games $333.29 255 4.8 311 SKU-001347
1348 Mega Health & Beauty Product Mini Health & Beauty $722.72 85 1.8 13 SKU-001348
1350 Professional Office Supplies Product Mini Office Supplies $188.27 44 3.2 16 SKU-001350
1352 Super Sports & Outdoors Product Classic Sports & Outdoors $201.95 259 1.1 316 SKU-001352
1353 Professional Toys & Games Product Plus Toys & Games $764.40 111 3.8 546 SKU-001353
1354 Standard Food & Grocery Product Lite Food & Grocery $704.98 84 3.6 394 SKU-001354
1355 Super Sports & Outdoors Product Special Edition Sports & Outdoors $468.33 139 1.4 277 SKU-001355
1356 Professional Food & Grocery Product Advanced Food & Grocery $464.59 416 3.0 401 SKU-001356
1357 Super Electronics Product Advanced Electronics $788.28 124 3.8 644 SKU-001357
1358 Standard Clothing Product 2024 Clothing $198.25 343 4.2 756 SKU-001358
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