Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

47 ms

Page Size

25

Current Page

611 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 611 Results Showing 15251 - 15275 of 24441

ID Name Category Price Stock Rating Reviews SKU
15810 Bulk Product a7e2c2ea Home & Garden $244.59 273 2.7 87 BULK-48073f32
15811 Bulk Product 747ac9f7 Home & Garden $841.55 103 3.8 70 BULK-95986572
15812 Bulk Product bb0cd8c3 Home & Garden $634.50 29 2.8 44 BULK-eaeaa099
15813 Bulk Product ef10ac09 Toys & Games $916.18 352 1.3 3 BULK-2a5ff5ea
15814 Bulk Product 180ea791 Home & Garden $813.36 437 3.4 39 BULK-5416847f
15815 Bulk Product 35683925 Clothing $263.08 217 0.4 0 BULK-d422be39
15816 Bulk Product 0a9be595 Clothing $11.83 44 0.8 25 BULK-96e98a97
15817 Bulk Product 7c2d3420 Clothing $432.35 397 4.6 96 BULK-31dfde2b
15818 Bulk Product 8fa59f53 Electronics $306.82 168 0.4 91 BULK-6b42ebfe
15819 Bulk Product 886a9b34 Toys & Games $370.41 411 1.2 97 BULK-306b111a
15820 Bulk Product bcf0ff16 Sports & Outdoors $643.60 345 0.6 78 BULK-04492d9a
15821 Bulk Product 2d6cfac8 Books $374.30 56 4.7 80 BULK-a56e022d
15822 Bulk Product fd8a693b Books $862.03 341 4.0 78 BULK-011305e6
15823 Bulk Product f885df92 Sports & Outdoors $956.57 175 3.2 76 BULK-72f0b955
15824 Bulk Product 5319ae33 Home & Garden $813.86 76 1.6 90 BULK-1c27e4b3
15825 Bulk Product 24a7a03a Home & Garden $140.87 128 2.2 33 BULK-73b69529
15826 Bulk Product 7b190c49 Books $23.35 433 3.2 17 BULK-a512a22c
15827 Bulk Product 687c57a5 Home & Garden $661.27 398 4.7 48 BULK-724e056b
15828 Bulk Product 74150d2a Toys & Games $308.74 164 3.8 69 BULK-e46781d9
15829 Bulk Product 8598c328 Sports & Outdoors $221.97 402 2.2 36 BULK-931cc762
15830 Bulk Product bbb7934e Books $101.98 340 1.4 9 BULK-093791ba
15831 Bulk Product 69285af0 Sports & Outdoors $396.79 168 2.1 65 BULK-c8c39db7
15832 Bulk Product 8d3abc38 Clothing $841.97 432 0.8 94 BULK-d12c32d6
15833 Bulk Product dbe7bde8 Clothing $850.21 228 4.1 46 BULK-6b7f4da4
15834 Bulk Product 7472cc8e Toys & Games $530.05 371 4.1 75 BULK-ec145cd1
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