Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

1457 ms

Page Size

25

Current Page

430 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 430 Results Showing 10726 - 10750 of 24441

ID Name Category Price Stock Rating Reviews SKU
11285 Bulk Product 53ba9cc9 Clothing $136.87 395 3.8 53 BULK-a8ac26e8
11286 Bulk Product f5b69bdd Home & Garden $89.96 37 1.9 63 BULK-723227f3
11287 Bulk Product 8fd37b2c Clothing $355.26 17 0.9 2 BULK-cc18988b
11288 Bulk Product 7dc3fbae Toys & Games $1,009.93 416 4.4 84 BULK-d9fd61fa
11289 Bulk Product d68290b9 Toys & Games $339.76 22 1.0 81 BULK-9dcfb8fd
11290 Bulk Product 84dbe2af Books $34.89 74 1.5 67 BULK-551248cb
11291 Bulk Product a94536df Electronics $228.34 149 0.1 4 BULK-a6dc2d30
11292 Bulk Product 41f8eabf Clothing $713.88 160 3.0 36 BULK-c4f82762
11293 Bulk Product df1b0881 Home & Garden $494.67 60 0.7 96 BULK-40022cea
11294 Bulk Product ec09664e Sports & Outdoors $553.55 359 4.2 65 BULK-c567a464
11295 Bulk Product 842d97a2 Books $341.38 219 4.4 44 BULK-2de01958
11296 Bulk Product dffd2a6c Electronics $786.61 380 4.8 73 BULK-54aed59e
11297 Bulk Product 08f8149b Toys & Games $123.80 357 1.8 94 BULK-9287edca
11298 Bulk Product f21125b2 Toys & Games $19.98 389 4.7 95 BULK-eacc1a06
11299 Bulk Product 305c788e Toys & Games $900.98 171 0.7 50 BULK-89dd80bb
11300 Bulk Product edfe3fe9 Clothing $74.20 413 3.9 94 BULK-fb3bd5c5
11301 Bulk Product e90743ca Home & Garden $118.94 246 2.0 90 BULK-cbdcfe22
11302 Bulk Product 25fa6f21 Electronics $61.62 169 4.4 59 BULK-b78318c3
11303 Bulk Product f5309f22 Home & Garden $522.54 276 1.8 32 BULK-dc67989e
11304 Bulk Product 6443dc87 Sports & Outdoors $617.50 185 4.3 31 BULK-13d161e4
11305 Bulk Product 3819cc0c Books $736.09 288 0.3 59 BULK-2c1a92b6
11306 Bulk Product 0a362230 Electronics $547.77 485 4.1 54 BULK-7ee1b201
11307 Bulk Product 5abc8eb1 Home & Garden $528.14 258 3.8 19 BULK-f0998060
11308 Bulk Product 9144cb58 Clothing $800.73 484 4.5 95 BULK-117a8a2c
11309 Bulk Product bda4b5d9 Clothing $976.85 333 4.1 67 BULK-dc9d6773
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