Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

637 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 637 Results Showing 15901 - 15925 of 24441

ID Name Category Price Stock Rating Reviews SKU
16460 Bulk Product 8eca12e1 Books $339.27 362 2.1 11 BULK-63b9aaf7
16461 Bulk Product 50b40bf0 Electronics $58.41 107 2.3 79 BULK-d3b3bd5b
16462 Bulk Product 5257c4c9 Books $405.64 129 3.0 9 BULK-66cd1f0a
16463 Bulk Product 868927c1 Toys & Games $762.94 79 1.0 59 BULK-b094219b
16464 Bulk Product 1c59e715 Electronics $754.82 365 1.0 11 BULK-ca87f022
16465 Bulk Product c6ebacc3 Toys & Games $384.82 436 0.3 40 BULK-9c4bb3d4
16466 Bulk Product b2661cbe Clothing $611.32 326 4.7 85 BULK-ce921bd1
16467 Bulk Product a59955b9 Clothing $557.37 131 1.5 0 BULK-8ff6a905
16468 Bulk Product 2f4f22e1 Sports & Outdoors $171.78 477 3.0 24 BULK-b48fd968
16469 Bulk Product 153d9397 Books $555.49 71 2.4 5 BULK-2afb1689
16470 Bulk Product 21b918ba Sports & Outdoors $617.66 153 4.8 85 BULK-0cdc8eb2
16471 Bulk Product 74e18308 Toys & Games $948.55 420 3.3 90 BULK-9e5aa9d8
16472 Bulk Product 21eb6b89 Books $411.22 205 2.8 86 BULK-a81a1955
16473 Bulk Product f44dbe17 Sports & Outdoors $813.70 59 3.8 40 BULK-2b0f580d
16474 Bulk Product b5a6474e Toys & Games $469.78 81 2.0 23 BULK-b15bac46
16475 Bulk Product 2caebaba Home & Garden $894.93 168 3.2 47 BULK-9cf9f864
16476 Bulk Product ee36873b Sports & Outdoors $622.45 413 4.0 77 BULK-c11a2d7b
16477 Bulk Product 0b903266 Electronics $952.33 257 0.6 52 BULK-b166ec01
16478 Bulk Product 12131fc3 Clothing $195.01 299 1.0 63 BULK-e1c5d98e
16479 Bulk Product 09bbd4f8 Books $308.88 405 1.7 16 BULK-a2e27bef
16480 Bulk Product 4d1767ec Clothing $348.65 488 3.8 34 BULK-063d72e4
16481 Bulk Product fd4e46ba Clothing $857.94 355 4.9 80 BULK-c5bcb696
16482 Bulk Product f4b6d60a Toys & Games $795.71 191 0.2 16 BULK-7b5e9ff5
16483 Bulk Product 47c36d11 Books $394.54 256 2.1 5 BULK-3b1b9ed6
16484 Bulk Product 4dde229c Home & Garden $1,009.84 180 2.9 96 BULK-0907cd40
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