Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

958 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 958 Results Showing 23926 - 23950 of 24441

ID Name Category Price Stock Rating Reviews SKU
24485 Bulk Product da417455 Home & Garden $182.98 131 1.7 83 BULK-f1a7320c
24486 Bulk Product b2067948 Toys & Games $606.41 260 4.4 83 BULK-3c26a2dc
24487 Bulk Product e61b9637 Books $31.64 191 2.2 80 BULK-407e0bb9
24488 Bulk Product 581f869d Home & Garden $445.31 449 1.0 1 BULK-75a0200c
24489 Bulk Product 2d08694d Clothing $68.15 338 2.6 43 BULK-ead5b48e
24490 Bulk Product 1603bb86 Clothing $342.95 98 1.8 39 BULK-c2314b27
24491 Bulk Product b5a3a787 Clothing $904.02 362 2.5 83 BULK-dc5dc87d
24492 Bulk Product 49fda88d Toys & Games $61.82 275 3.1 58 BULK-8971e480
24493 Bulk Product c7e1aaa5 Toys & Games $517.57 433 3.8 72 BULK-733eb796
24494 Bulk Product 982175f0 Home & Garden $798.52 172 0.4 71 BULK-68858d40
24495 Bulk Product 6bd50942 Toys & Games $222.61 125 4.6 45 BULK-f83a490b
24496 Bulk Product 8deece81 Home & Garden $218.65 181 4.8 72 BULK-4a711442
24497 Bulk Product 915e3d0e Sports & Outdoors $964.93 126 3.6 98 BULK-a4b49776
24498 Bulk Product 23f4e42b Toys & Games $746.28 454 3.3 11 BULK-b12642f7
24499 Bulk Product a5b0a9d7 Clothing $637.50 240 5.0 70 BULK-f7ca8c70
24500 Bulk Product 3b6ced14 Books $214.03 318 0.4 70 BULK-9bb49de4
24501 Bulk Product 2c9c8601 Home & Garden $305.53 234 1.0 53 BULK-7593fa36
24502 Bulk Product 68cee2d6 Books $998.60 386 2.1 49 BULK-ad5e40d0
24503 Bulk Product 38aa2df1 Electronics $888.75 103 2.9 55 BULK-7c7d7dee
24504 Bulk Product 5b6744b2 Home & Garden $793.16 204 4.3 18 BULK-35be1866
24505 Bulk Product d8df7574 Toys & Games $207.90 475 1.1 1 BULK-4d560a29
24506 Bulk Product d306cbcc Sports & Outdoors $638.58 446 3.2 77 BULK-530a93f2
24507 Bulk Product 5baa7cee Home & Garden $84.62 245 1.3 17 BULK-fef1bba3
24508 Bulk Product acf7213f Sports & Outdoors $173.49 401 0.6 85 BULK-42924661
24509 Bulk Product 1bd6ac8b Toys & Games $677.03 346 3.5 78 BULK-40ca3ae2
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