Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

441 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 441 Results Showing 11001 - 11025 of 24441

ID Name Category Price Stock Rating Reviews SKU
11560 Bulk Product c33f8045 Sports & Outdoors $259.32 165 2.0 55 BULK-48de9628
11561 Bulk Product 801e8766 Clothing $463.70 417 1.3 84 BULK-b5e8a6dd
11562 Bulk Product bdcba066 Electronics $958.46 273 0.2 39 BULK-77c1f1c8
11563 Bulk Product 484742bb Books $628.41 454 2.9 5 BULK-67e46133
11564 Bulk Product caafa100 Sports & Outdoors $206.58 423 4.1 92 BULK-975b493d
11565 Bulk Product a9a1fe22 Books $980.76 79 3.4 20 BULK-b0e669f3
11566 Bulk Product 9caf72a7 Toys & Games $863.95 240 4.2 81 BULK-f4cba846
11567 Bulk Product 2f4b0076 Books $109.50 374 0.1 89 BULK-dc8ccfb0
11568 Bulk Product 910f2785 Electronics $830.42 190 3.9 84 BULK-286d3938
11569 Bulk Product 03064742 Home & Garden $298.52 90 3.7 73 BULK-19e5ebdd
11570 Bulk Product 7f7e0191 Books $397.59 366 1.6 79 BULK-5552a5b1
11571 Bulk Product 8ebff88f Home & Garden $981.75 131 0.5 47 BULK-9ea07028
11572 Bulk Product 8901c828 Toys & Games $445.48 330 2.9 70 BULK-359f0d06
11573 Bulk Product 7f057a51 Books $391.86 219 3.6 61 BULK-d296d1d1
11574 Bulk Product bc3cc67f Clothing $171.96 136 0.4 24 BULK-7b614979
11575 Bulk Product 12def21a Home & Garden $591.90 390 0.2 77 BULK-2ce687df
11576 Bulk Product 7ceee9ee Electronics $298.87 477 0.7 46 BULK-dc61f283
11577 Bulk Product 1cf64a1b Sports & Outdoors $702.66 240 3.2 45 BULK-57b81d60
11578 Bulk Product 8f00f991 Sports & Outdoors $513.03 90 3.4 97 BULK-88358b07
11579 Bulk Product 600ea73e Clothing $767.04 259 0.9 78 BULK-0eee03ea
11580 Bulk Product 54d39773 Sports & Outdoors $49.88 86 0.6 54 BULK-39ed44d1
11581 Bulk Product 80d15d3e Electronics $350.60 489 0.3 37 BULK-d3e32b0e
11582 Bulk Product 4813e208 Sports & Outdoors $798.96 442 4.0 3 BULK-040da4f4
11583 Bulk Product d2acaf3e Toys & Games $369.83 434 3.2 93 BULK-a6a41df3
11584 Bulk Product 084851d3 Home & Garden $802.64 453 0.7 26 BULK-ed028809
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