Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

72 ms

Page Size

25

Current Page

976 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 976 Results Showing 24376 - 24400 of 24441

ID Name Category Price Stock Rating Reviews SKU
24935 Bulk Product 6ff07c47 Home & Garden $73.01 473 4.5 83 BULK-b664426f
24936 Bulk Product 425c935c Toys & Games $670.77 289 0.4 45 BULK-8aec43ff
24937 Bulk Product 01f2bf4a Electronics $607.92 105 0.6 59 BULK-89124d40
24938 Bulk Product aa06bffb Electronics $993.65 287 3.2 94 BULK-b6b339d6
24939 Bulk Product d97857a2 Clothing $307.42 139 1.9 82 BULK-5498d3c0
24940 Bulk Product ad1bebab Sports & Outdoors $149.08 94 3.0 45 BULK-42a38b53
24941 Bulk Product 1427ab93 Electronics $425.96 105 0.6 13 BULK-a4c77ccb
24942 Bulk Product cc9c6c33 Home & Garden $275.02 218 2.6 91 BULK-28a12fc1
24943 Bulk Product e2aba757 Home & Garden $158.63 51 1.5 34 BULK-d33c60d9
24944 Bulk Product 058126a7 Clothing $584.33 8 3.6 89 BULK-b9a9a29a
24945 Bulk Product ccb6a70c Home & Garden $921.64 156 1.3 95 BULK-f728d1a8
24946 Bulk Product db0cfec5 Home & Garden $298.90 331 3.3 77 BULK-ec03715b
24947 Bulk Product d5ef2f23 Toys & Games $485.09 2 2.5 42 BULK-36180295
24948 Bulk Product 74cf99aa Sports & Outdoors $774.69 215 0.5 41 BULK-f062af71
24949 Bulk Product 3c011398 Electronics $34.86 220 1.2 97 BULK-b58cce1f
24950 Bulk Product d518ab13 Toys & Games $491.45 306 3.1 32 BULK-d1a83724
24951 Bulk Product 50c9d003 Sports & Outdoors $460.09 59 1.4 14 BULK-e2c7bef5
24952 Bulk Product 4f3cdccb Home & Garden $347.68 82 1.6 46 BULK-30efad9c
24953 Bulk Product 933f0254 Home & Garden $69.79 322 0.3 25 BULK-8b51aeac
24954 Bulk Product eb2a8cec Home & Garden $382.35 99 3.2 21 BULK-11fbaabd
24955 Bulk Product 855d4072 Books $438.14 188 4.5 41 BULK-405c0741
24956 Bulk Product 0fac2fce Books $807.89 239 2.2 25 BULK-3851398d
24957 Bulk Product d582616f Toys & Games $737.77 382 2.5 22 BULK-78305ddd
24958 Bulk Product 75671e12 Books $504.72 461 1.7 37 BULK-75903212
24959 Bulk Product 6e8cfa1b Clothing $250.99 357 2.5 24 BULK-cac2bf9b
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