Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

342 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 342 Results Showing 8526 - 8550 of 24441

ID Name Category Price Stock Rating Reviews SKU
9085 Bulk Product 6ff8a6ac Books $572.54 285 1.2 99 BULK-a7b85511
9086 Bulk Product 2c978258 Home & Garden $530.71 362 3.4 57 BULK-0950be44
9087 Bulk Product b61556fd Clothing $467.94 139 3.6 3 BULK-f10279ca
9088 Bulk Product 5b14454f Toys & Games $450.79 109 2.7 9 BULK-bd833381
9089 Bulk Product 4e6e6c80 Books $445.08 127 4.2 51 BULK-ede62b97
9090 Bulk Product ef7110a3 Clothing $555.48 62 0.1 38 BULK-c93daada
9091 Bulk Product 885db70f Home & Garden $59.80 493 4.3 80 BULK-baa17d32
9092 Bulk Product 4218216e Toys & Games $204.94 175 0.2 58 BULK-a709b070
9093 Bulk Product 9ee5848c Toys & Games $320.27 144 4.1 49 BULK-c7343728
9094 Bulk Product e5b92a9d Electronics $292.72 72 2.6 68 BULK-fab7166e
9095 Bulk Product c0fb13ae Books $1,008.75 424 2.8 60 BULK-a17de34d
9096 Bulk Product 2083a182 Books $469.10 146 3.8 32 BULK-58a76bf0
9097 Bulk Product 0fb573f7 Home & Garden $298.59 144 2.0 74 BULK-e0516557
9098 Bulk Product 84e50b30 Home & Garden $707.71 481 2.7 61 BULK-a3dabb8b
9099 Bulk Product b6626dc1 Clothing $60.38 348 3.8 61 BULK-66108c25
9100 Bulk Product b9c348f9 Sports & Outdoors $826.22 68 4.7 7 BULK-3e2983b1
9101 Bulk Product 34d4e6b2 Home & Garden $997.01 368 3.3 19 BULK-134249ee
9102 Bulk Product 02404753 Clothing $360.97 386 3.8 42 BULK-42daeb6c
9103 Bulk Product 61f075cb Clothing $220.79 244 3.5 88 BULK-196ce97c
9104 Bulk Product fabe1df4 Clothing $794.59 244 1.5 32 BULK-36951ffe
9105 Bulk Product 014c5742 Books $500.22 112 3.1 28 BULK-479958de
9106 Bulk Product 424aebf4 Electronics $172.30 73 4.7 73 BULK-06bc989f
9107 Bulk Product 5e631bd7 Books $849.29 442 0.0 75 BULK-f490f99d
9108 Bulk Product 65bce243 Toys & Games $1,002.94 28 2.8 41 BULK-11eacb85
9109 Bulk Product 73658468 Toys & Games $30.38 98 1.2 83 BULK-e26fc7ef
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