Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

679 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 679 Results Showing 16951 - 16975 of 24441

ID Name Category Price Stock Rating Reviews SKU
17510 Bulk Product 2e0a6e7a Electronics $728.37 38 1.5 1 BULK-08263b18
17511 Bulk Product b1527bb9 Sports & Outdoors $504.46 165 2.5 37 BULK-dedd37c4
17512 Bulk Product 04658b50 Books $904.46 408 4.8 10 BULK-9cf1ec9c
17513 Bulk Product 5bb6436f Toys & Games $787.62 240 4.5 5 BULK-2e51b76a
17514 Bulk Product afa7012a Toys & Games $820.75 455 1.1 57 BULK-817a9982
17515 Bulk Product 80d978e0 Sports & Outdoors $510.23 460 1.0 8 BULK-21be3bb6
17516 Bulk Product 54e062e9 Home & Garden $524.11 230 3.8 7 BULK-6a5e3c2b
17517 Bulk Product 408adabc Clothing $129.30 71 1.2 97 BULK-3ac49347
17518 Bulk Product 4676395d Electronics $787.36 445 3.7 46 BULK-afbb25ab
17519 Bulk Product a9439bb1 Sports & Outdoors $397.29 389 0.1 37 BULK-45633940
17520 Bulk Product 49813e75 Clothing $508.29 386 4.3 70 BULK-acff53fd
17521 Bulk Product 0996c0e0 Books $897.14 256 2.5 22 BULK-edaef024
17522 Bulk Product 1c79a29c Sports & Outdoors $900.58 166 3.2 13 BULK-1dce1311
17523 Bulk Product 338c49ce Electronics $630.39 27 2.4 67 BULK-3d78bdba
17524 Bulk Product df7b04bf Home & Garden $369.72 128 4.9 39 BULK-fb2c7f94
17525 Bulk Product 6b08f8a2 Books $570.46 116 3.7 62 BULK-e519c868
17526 Bulk Product d9966e08 Electronics $971.48 5 3.1 39 BULK-1fb1ec6a
17527 Bulk Product 3a6758e7 Clothing $932.02 244 4.7 6 BULK-85a2e732
17528 Bulk Product f4fb3153 Books $960.37 386 3.4 36 BULK-45641243
17529 Bulk Product a619f205 Home & Garden $900.56 368 0.2 37 BULK-6df11652
17530 Bulk Product 8f7275ff Clothing $820.08 308 1.7 71 BULK-b3e5144c
17531 Bulk Product 72457320 Toys & Games $708.38 122 3.5 36 BULK-471592bc
17532 Bulk Product ab00243d Electronics $623.36 252 3.4 79 BULK-f191e652
17533 Bulk Product b7576253 Home & Garden $736.12 62 4.1 4 BULK-0372b6ff
17534 Bulk Product 13a4d786 Home & Garden $874.93 351 0.1 15 BULK-9c60dca0
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