Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

43 ms

Page Size

25

Current Page

955 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 955 Results Showing 23851 - 23875 of 24441

ID Name Category Price Stock Rating Reviews SKU
24410 Bulk Product b3541d66 Sports & Outdoors $265.68 376 0.0 77 BULK-1dc3e9ac
24411 Bulk Product 14a000ff Clothing $669.85 347 4.8 63 BULK-c61d8608
24412 Bulk Product 7c29b80b Electronics $381.71 164 4.0 34 BULK-498201ca
24413 Bulk Product 08c60649 Sports & Outdoors $160.88 171 1.9 85 BULK-476003d8
24414 Bulk Product c0bb5324 Home & Garden $664.97 127 0.8 51 BULK-021142d7
24415 Bulk Product 8b7ab470 Sports & Outdoors $900.18 54 4.4 66 BULK-173cb2bc
24416 Bulk Product e1b57a1e Toys & Games $402.97 237 0.7 44 BULK-88bd846c
24417 Bulk Product c871b91b Toys & Games $294.79 70 1.1 38 BULK-4c723f6a
24418 Bulk Product 943d264e Electronics $217.35 462 2.9 16 BULK-7aa2c3de
24419 Bulk Product cfa88c61 Sports & Outdoors $39.11 298 1.3 8 BULK-18647c1d
24420 Bulk Product 7efd0da4 Clothing $380.91 139 1.8 11 BULK-98f8af10
24421 Bulk Product 54bc94d2 Sports & Outdoors $133.87 294 0.7 73 BULK-93dade3b
24422 Bulk Product 1fb1a53e Books $881.29 184 4.7 41 BULK-a34f10b7
24423 Bulk Product a7fe6acd Clothing $508.83 192 3.5 55 BULK-a4496dd1
24424 Bulk Product 16a08167 Sports & Outdoors $999.37 365 4.8 46 BULK-a03e0ba7
24425 Bulk Product c8c2f2a0 Electronics $866.03 305 2.5 1 BULK-660f65d7
24426 Bulk Product e813589b Sports & Outdoors $77.49 479 0.1 15 BULK-61cfed1e
24427 Bulk Product 464f6bde Books $114.10 200 0.3 57 BULK-353e3b43
24428 Bulk Product e3c9d37b Clothing $533.46 30 1.9 61 BULK-c20fa4c4
24429 Bulk Product 499f4f64 Books $481.60 376 1.3 78 BULK-7a1c4122
24430 Bulk Product 88346b44 Clothing $393.59 73 3.0 28 BULK-bd31dca4
24431 Bulk Product 2a74df30 Sports & Outdoors $925.91 307 0.3 60 BULK-df56c265
24432 Bulk Product 74267102 Clothing $933.55 64 3.4 39 BULK-53706247
24433 Bulk Product 332bc0db Toys & Games $402.15 60 3.8 18 BULK-37f48069
24434 Bulk Product 760b108b Sports & Outdoors $940.33 457 3.0 23 BULK-9e5bccf4
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