Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

25

Current Page

544 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 544 Results Showing 13576 - 13600 of 24441

ID Name Category Price Stock Rating Reviews SKU
14135 Bulk Product 1ce76f2c Sports & Outdoors $316.19 250 2.4 96 BULK-bc0d6c38
14136 Bulk Product b391228f Clothing $564.60 178 3.6 3 BULK-a0a23c47
14137 Bulk Product aab856a0 Electronics $772.94 101 0.8 37 BULK-75b72c1b
14138 Bulk Product fc724f79 Books $885.63 278 0.7 39 BULK-438e6e84
14139 Bulk Product 68dd3cfd Electronics $63.59 295 1.2 56 BULK-fba5bcd9
14140 Bulk Product bf0de752 Toys & Games $918.22 152 3.0 10 BULK-1a7b9fe6
14141 Bulk Product b43cd666 Home & Garden $23.80 218 0.3 42 BULK-11c3ac7f
14142 Bulk Product ed4a2498 Clothing $54.79 437 4.2 70 BULK-026a8c2e
14143 Bulk Product 66704411 Books $331.62 133 5.0 60 BULK-82aadc2c
14144 Bulk Product 16c0a1e9 Books $764.00 357 4.6 13 BULK-d6aaf0cf
14145 Bulk Product e5d366d9 Toys & Games $514.92 235 1.4 87 BULK-22e59e68
14146 Bulk Product 3245a3f9 Electronics $232.15 163 2.2 95 BULK-24dca437
14147 Bulk Product 536b7732 Electronics $48.84 42 4.7 83 BULK-815f0f73
14148 Bulk Product 784828f2 Sports & Outdoors $850.54 54 4.1 88 BULK-2d15a5e0
14149 Bulk Product 0571e94a Electronics $487.49 147 2.3 78 BULK-b96bf239
14150 Bulk Product cb564b5d Toys & Games $336.36 336 3.4 27 BULK-6a39e9f9
14151 Bulk Product b2881e5f Books $381.01 372 4.0 17 BULK-cdabf268
14152 Bulk Product e5c218c1 Sports & Outdoors $758.74 89 4.7 66 BULK-740fef89
14153 Bulk Product d6bb659d Toys & Games $669.41 385 4.0 25 BULK-8cd318cd
14154 Bulk Product 56ca899e Electronics $720.23 320 1.2 56 BULK-e5cf57c1
14155 Bulk Product 9a555555 Home & Garden $266.28 499 4.5 71 BULK-ec21896b
14156 Bulk Product 3904954e Home & Garden $716.40 81 0.0 36 BULK-f0ddc143
14157 Bulk Product f9a64bc9 Clothing $378.28 239 0.7 43 BULK-9101b5c0
14158 Bulk Product 221cf566 Books $117.21 480 0.9 11 BULK-89021943
14159 Bulk Product b8852a87 Books $55.88 262 0.6 36 BULK-e8d9e037
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