Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

13 ms

Page Size

25

Current Page

649 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 649 Results Showing 16201 - 16225 of 24441

ID Name Category Price Stock Rating Reviews SKU
16760 Bulk Product f42be8a9 Electronics $500.06 294 0.1 69 BULK-5413ef4a
16761 Bulk Product fc872a0b Clothing $743.50 216 0.5 87 BULK-52e31ccf
16762 Bulk Product d7468b0b Toys & Games $310.91 402 4.7 23 BULK-e5e816b9
16763 Bulk Product 000d03a6 Electronics $557.35 216 4.7 4 BULK-5cf3057b
16764 Bulk Product 9b94aeba Sports & Outdoors $100.37 0 0.7 1 BULK-2794ebfe
16765 Bulk Product 230cdac5 Toys & Games $607.25 232 0.3 63 BULK-ac9eace9
16766 Bulk Product 56213102 Clothing $197.72 175 1.6 98 BULK-e7f947f3
16767 Bulk Product 05386984 Home & Garden $890.08 281 4.1 26 BULK-bf25547e
16768 Bulk Product 1eb47090 Home & Garden $402.84 81 4.0 59 BULK-104b0708
16769 Bulk Product ebe01b1f Books $117.90 308 0.3 4 BULK-d44d5b25
16770 Bulk Product 1d2baaf7 Electronics $529.07 385 0.1 23 BULK-0814a1c1
16771 Bulk Product bf0e4fb0 Home & Garden $837.21 29 0.7 26 BULK-47026ab3
16772 Bulk Product 0719a677 Clothing $940.21 458 3.1 88 BULK-2a653cb6
16773 Bulk Product cee25ef8 Toys & Games $243.59 364 2.5 88 BULK-4d45c990
16774 Bulk Product 99dfeac0 Books $962.37 65 2.8 6 BULK-120f1f8b
16775 Bulk Product bd0bfe37 Home & Garden $904.55 469 0.8 6 BULK-359ecc2e
16776 Bulk Product 6415a2f2 Books $638.82 343 1.8 42 BULK-7c10010a
16777 Bulk Product 2bacaf96 Electronics $367.56 65 0.7 30 BULK-c7d8d8bc
16778 Bulk Product 4b409064 Clothing $834.65 10 4.6 17 BULK-eee59133
16779 Bulk Product e7840b48 Toys & Games $30.45 127 4.0 84 BULK-f0101e3a
16780 Bulk Product 1183844b Books $841.95 181 3.8 99 BULK-00ed1c17
16781 Bulk Product 5ff68981 Sports & Outdoors $749.60 422 3.6 89 BULK-955ad9e1
16782 Bulk Product cb559963 Home & Garden $608.24 163 3.5 6 BULK-81a03000
16783 Bulk Product c7550743 Home & Garden $971.51 380 3.4 31 BULK-25e13d96
16784 Bulk Product 8c8bd9e3 Home & Garden $190.99 136 4.6 12 BULK-d966281c
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