Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

9 ms

Page Size

25

Current Page

294 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 294 Results Showing 7326 - 7350 of 24441

ID Name Category Price Stock Rating Reviews SKU
7885 Bulk Product bfe0185c Home & Garden $360.42 58 0.6 30 BULK-bf4569d2
7886 Bulk Product 78adee87 Books $778.47 300 2.8 70 BULK-9fac1173
7887 Bulk Product 620f8c74 Clothing $180.47 284 1.1 32 BULK-3264e61c
7888 Bulk Product c4ca9421 Books $860.84 365 0.2 91 BULK-08485ebf
7889 Bulk Product 7a124446 Home & Garden $903.95 458 4.0 33 BULK-58165f92
7890 Bulk Product d6be262a Home & Garden $423.40 85 3.9 91 BULK-f81923d8
7891 Bulk Product 232bdb77 Books $688.62 229 1.5 24 BULK-07a98278
7892 Bulk Product 73850c0a Home & Garden $703.51 478 2.9 87 BULK-85d6dee2
7893 Bulk Product 6f4fac36 Home & Garden $608.50 32 2.1 81 BULK-802f35ec
7894 Bulk Product 29ea5b30 Sports & Outdoors $455.30 320 2.5 16 BULK-443367ae
7895 Bulk Product 045d3e50 Sports & Outdoors $663.59 391 2.1 3 BULK-60fcc418
7896 Bulk Product 541ba533 Sports & Outdoors $895.25 133 3.1 91 BULK-0accf48d
7897 Bulk Product 5b4abd40 Home & Garden $825.45 320 1.1 0 BULK-1c07fa50
7898 Bulk Product 4eb7d4af Books $654.86 13 1.9 12 BULK-c2ec9d0d
7899 Bulk Product b739e689 Books $232.24 459 4.3 95 BULK-cef09a72
7900 Bulk Product 8a91595d Sports & Outdoors $316.37 435 0.3 17 BULK-d3fa00f3
7901 Bulk Product d60853bc Sports & Outdoors $931.63 469 2.8 68 BULK-28f5bd14
7902 Bulk Product 2f130432 Home & Garden $775.65 139 1.1 67 BULK-a8f392b6
7903 Bulk Product f43a393a Books $381.05 14 2.8 61 BULK-5df5627a
7904 Bulk Product be9d3a28 Home & Garden $587.03 401 0.9 97 BULK-a15fbe06
7905 Bulk Product 16af017d Toys & Games $395.81 318 0.5 25 BULK-5f300586
7906 Bulk Product d214e6dd Clothing $269.53 366 0.8 41 BULK-c5e8ccea
7907 Bulk Product e856e94c Sports & Outdoors $122.66 398 4.8 28 BULK-c6be2fb3
7908 Bulk Product dc50a28d Home & Garden $698.53 19 1.9 52 BULK-c3905270
7909 Bulk Product 628f29bb Home & Garden $340.11 178 0.0 78 BULK-af2b2297
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