Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

25

Current Page

428 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 428 Results Showing 10676 - 10700 of 24441

ID Name Category Price Stock Rating Reviews SKU
11235 Bulk Product 123ca437 Sports & Outdoors $590.15 13 0.8 17 BULK-843ba732
11236 Bulk Product 2beb65d9 Electronics $601.65 231 0.1 48 BULK-244da4a6
11237 Bulk Product 97565b8d Home & Garden $18.64 138 2.0 83 BULK-d1d0df2e
11238 Bulk Product 6263a809 Home & Garden $169.24 39 0.5 55 BULK-16ec46af
11239 Bulk Product 3a70814b Home & Garden $423.73 406 5.0 18 BULK-43661903
11240 Bulk Product 7b0c1dae Books $127.37 382 4.1 7 BULK-a512831d
11241 Bulk Product c3c2c5f6 Home & Garden $320.99 163 2.9 78 BULK-0304d0c2
11242 Bulk Product 4528a579 Electronics $923.69 102 3.2 67 BULK-f015276d
11243 Bulk Product 0ec482af Sports & Outdoors $45.07 466 3.7 41 BULK-8226c0b1
11244 Bulk Product ea24902b Home & Garden $279.83 410 0.6 31 BULK-bbdd0753
11245 Bulk Product 80fabf2b Toys & Games $258.12 31 1.5 14 BULK-3becf676
11246 Bulk Product ddea1036 Home & Garden $308.62 276 1.5 39 BULK-0d8240d5
11247 Bulk Product c973a387 Toys & Games $1,002.30 366 0.4 38 BULK-ebbc7a3e
11248 Bulk Product c268a002 Toys & Games $852.21 342 2.4 14 BULK-93bc3803
11249 Bulk Product 0c739b50 Sports & Outdoors $801.45 420 4.8 18 BULK-36a5d2fd
11250 Bulk Product 698bdcd2 Books $184.38 41 1.9 91 BULK-bddacf76
11251 Bulk Product 12547af9 Toys & Games $757.85 370 2.6 11 BULK-3ddcbd74
11252 Bulk Product 02c3be01 Electronics $153.39 197 4.6 43 BULK-3a226f5f
11253 Bulk Product 397d0e14 Toys & Games $119.43 183 0.3 69 BULK-9d3e5707
11254 Bulk Product 28895b15 Clothing $10.43 210 4.4 43 BULK-2732a165
11255 Bulk Product 986936c4 Sports & Outdoors $324.86 107 0.4 6 BULK-4af28eaf
11256 Bulk Product d63202c8 Electronics $155.59 390 3.0 46 BULK-59a2e509
11257 Bulk Product a032ef00 Books $31.14 449 3.5 12 BULK-08ec94d7
11258 Bulk Product b70f3cc4 Clothing $406.47 175 4.6 74 BULK-4395ecde
11259 Bulk Product 4dc13047 Clothing $913.04 116 3.5 87 BULK-b4b4e2c3
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