Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

42 ms

Page Size

25

Current Page

529 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 529 Results Showing 13201 - 13225 of 24441

ID Name Category Price Stock Rating Reviews SKU
13760 Bulk Product 283194c4 Clothing $745.91 92 0.7 4 BULK-f378b9e9
13761 Bulk Product 52ee2a5d Sports & Outdoors $75.05 103 4.9 99 BULK-14db8679
13762 Bulk Product 20418c51 Home & Garden $387.75 220 1.1 63 BULK-f9c53d97
13763 Bulk Product 8d8e7886 Books $440.92 491 0.9 43 BULK-0f5c4cd2
13764 Bulk Product e417c3e5 Books $812.97 325 5.0 33 BULK-8b2b44de
13765 Bulk Product b66a360f Toys & Games $970.80 223 3.8 80 BULK-0a82e11d
13766 Bulk Product 05ddfac5 Electronics $541.56 374 3.6 88 BULK-01692ac4
13767 Bulk Product a0923f36 Electronics $139.51 30 3.4 7 BULK-8b866878
13768 Bulk Product 7e3950c2 Electronics $851.50 40 0.1 38 BULK-f1f88f03
13769 Bulk Product 353760a3 Sports & Outdoors $1,004.43 360 0.2 27 BULK-0d0635cc
13770 Bulk Product 9642b9ca Toys & Games $1,004.19 427 2.1 74 BULK-c260d7a7
13771 Bulk Product 718ab510 Electronics $254.25 327 1.8 20 BULK-202b91fa
13772 Bulk Product 62da414f Home & Garden $474.62 196 1.3 55 BULK-9cf0fa9e
13773 Bulk Product 609aad49 Toys & Games $619.64 93 0.6 21 BULK-9a3cdd52
13774 Bulk Product d9fb08be Electronics $118.83 350 2.0 25 BULK-558660aa
13775 Bulk Product d9e21d5f Home & Garden $421.36 173 3.7 8 BULK-5c3aa1ac
13776 Bulk Product 0f142d29 Electronics $233.12 472 2.5 81 BULK-430547bd
13777 Bulk Product 8fee7d77 Books $495.53 58 2.1 49 BULK-99807d2c
13778 Bulk Product 12c5e94e Clothing $185.46 265 1.3 17 BULK-8bd5f55c
13779 Bulk Product 9bd333f0 Home & Garden $237.05 103 1.4 50 BULK-66c9e219
13780 Bulk Product f1d45430 Sports & Outdoors $698.44 43 3.9 28 BULK-2315c720
13781 Bulk Product 26c5775e Books $832.55 309 1.2 10 BULK-f7b53987
13782 Bulk Product 9f66fd1e Home & Garden $638.98 92 0.8 84 BULK-f9ae5f6d
13783 Bulk Product adf3de56 Electronics $240.54 338 4.9 71 BULK-f47559d8
13784 Bulk Product 116f096b Electronics $626.35 193 3.3 34 BULK-ccfc9b5a
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