Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

942 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 942 Results Showing 23526 - 23550 of 24441

ID Name Category Price Stock Rating Reviews SKU
24085 Bulk Product 079620d6 Home & Garden $396.32 21 4.5 21 BULK-af0236cd
24086 Bulk Product 45c3b45b Clothing $321.92 356 0.0 92 BULK-ebbb5e84
24087 Bulk Product ec567524 Clothing $13.07 403 2.9 98 BULK-235449e0
24088 Bulk Product 827e3281 Clothing $159.23 51 4.4 57 BULK-801d2e5e
24089 Bulk Product bcfafef6 Books $912.81 0 4.0 77 BULK-023e2e6e
24090 Bulk Product dd0f3124 Electronics $751.19 496 1.3 76 BULK-9d918f53
24091 Bulk Product 8eefbe82 Books $367.99 344 2.0 79 BULK-37aebd34
24092 Bulk Product 8cec1f50 Electronics $907.26 10 4.8 87 BULK-2ef88571
24093 Bulk Product 27a83703 Toys & Games $23.13 353 2.5 99 BULK-f08402c6
24094 Bulk Product 386febee Toys & Games $542.07 402 4.7 37 BULK-e0b8ebec
24095 Bulk Product a30908e4 Books $410.92 292 0.8 81 BULK-b37fa4af
24096 Bulk Product 9ad90c91 Home & Garden $215.45 306 4.7 31 BULK-42c89913
24097 Bulk Product 58327ee4 Toys & Games $904.55 461 5.0 82 BULK-5804fa4e
24098 Bulk Product d8ed4b10 Books $489.53 3 2.2 54 BULK-8cd1e1f7
24099 Bulk Product f563c04e Clothing $486.00 42 2.8 15 BULK-5ca01031
24100 Bulk Product 00d60974 Home & Garden $134.05 310 2.4 39 BULK-5f2c6d2a
24101 Bulk Product e1d625f8 Books $673.36 6 2.8 34 BULK-d05813e6
24102 Bulk Product 6611761e Toys & Games $933.96 111 3.0 59 BULK-2893fa73
24103 Bulk Product 338f02b4 Electronics $842.15 417 2.5 26 BULK-daf13dfc
24104 Bulk Product 33415369 Books $752.69 429 3.1 32 BULK-f5072341
24105 Bulk Product 026408f1 Toys & Games $732.47 12 1.0 48 BULK-344d7d26
24106 Bulk Product fed07be5 Clothing $540.14 284 2.0 26 BULK-7a287581
24107 Bulk Product 81a17f97 Toys & Games $952.74 115 0.3 81 BULK-f2de5281
24108 Bulk Product d6b38574 Toys & Games $527.41 370 1.1 69 BULK-d61ca477
24109 Bulk Product bde8c1dd Home & Garden $937.33 56 0.2 51 BULK-c7347527
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