Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

25

Current Page

463 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 463 Results Showing 11551 - 11575 of 24441

ID Name Category Price Stock Rating Reviews SKU
12110 Bulk Product 43f89236 Sports & Outdoors $880.43 10 2.4 81 BULK-a1d5c88d
12111 Bulk Product b5171604 Sports & Outdoors $656.11 255 2.0 41 BULK-aa8d16ae
12112 Bulk Product bbabce0d Electronics $559.64 279 2.7 39 BULK-cf943c35
12113 Bulk Product 6819ace5 Toys & Games $228.85 489 1.2 83 BULK-f376e87c
12114 Bulk Product d3066af6 Sports & Outdoors $861.41 169 0.8 98 BULK-1f6e4e99
12115 Bulk Product f2409eda Clothing $505.59 190 2.7 28 BULK-3c7122e7
12116 Bulk Product f73734fe Books $89.39 442 1.2 50 BULK-8c4210f0
12117 Bulk Product 515523e0 Home & Garden $226.59 463 0.8 38 BULK-5ff80a3b
12118 Bulk Product 746bcb02 Toys & Games $228.11 387 3.5 16 BULK-55e4eea6
12119 Bulk Product 6b330ad4 Electronics $485.10 299 0.1 45 BULK-9ac52818
12120 Bulk Product 9c552d58 Home & Garden $255.73 485 2.8 48 BULK-ec0442e2
12121 Bulk Product c73aa4bf Home & Garden $824.73 259 4.1 5 BULK-fef2f9b7
12122 Bulk Product 498b5adc Electronics $168.70 475 3.6 98 BULK-4a4bef8c
12123 Bulk Product 82e55dd9 Electronics $407.68 267 4.5 40 BULK-4a9d5c37
12124 Bulk Product 00ef4a07 Toys & Games $897.97 119 0.9 96 BULK-05b764d1
12125 Bulk Product f8b6fddc Sports & Outdoors $858.14 498 2.7 32 BULK-cc3f87d4
12126 Bulk Product 579711a0 Books $638.21 147 1.9 90 BULK-284915c4
12127 Bulk Product d3e3f3a1 Home & Garden $931.12 281 2.0 16 BULK-ff1b305f
12128 Bulk Product 7862dcef Electronics $39.66 422 3.1 48 BULK-9d32452f
12129 Bulk Product 691855cd Electronics $889.60 460 2.8 50 BULK-185f6069
12130 Bulk Product ad6dbdd9 Books $209.08 136 3.5 69 BULK-f3e8adbb
12131 Bulk Product dd04bf41 Electronics $724.31 28 3.1 65 BULK-9979aefe
12132 Bulk Product 455b867a Toys & Games $270.04 322 1.3 61 BULK-86b0bbea
12133 Bulk Product bf04d634 Clothing $433.67 249 4.4 99 BULK-bbaf049f
12134 Bulk Product 1610cf1b Sports & Outdoors $297.60 480 3.1 78 BULK-12bc6260
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