Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

341 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 341 Results Showing 8501 - 8525 of 24441

ID Name Category Price Stock Rating Reviews SKU
9060 Bulk Product a076efa0 Sports & Outdoors $268.51 201 3.5 19 BULK-756f7ab4
9061 Bulk Product a62c0493 Sports & Outdoors $965.01 246 1.3 39 BULK-fd7a44ba
9062 Bulk Product d202a6ab Home & Garden $963.40 108 3.0 83 BULK-fea9f07b
9063 Bulk Product e526e968 Books $568.40 201 0.8 0 BULK-2e10ae5b
9064 Bulk Product 41cbd65a Toys & Games $902.29 148 0.1 80 BULK-e7258317
9065 Bulk Product 28282d28 Clothing $136.20 221 1.6 96 BULK-ed0434d3
9066 Bulk Product a7e8fc2c Books $787.10 10 1.6 52 BULK-9238e317
9067 Bulk Product c27adf0e Electronics $495.81 355 0.0 31 BULK-7a8e4c07
9068 Bulk Product 4fd79a7e Sports & Outdoors $218.30 168 2.4 69 BULK-78870435
9069 Bulk Product f2a9d8c6 Clothing $988.56 393 2.6 61 BULK-be77fca7
9070 Bulk Product 503ccc4f Clothing $873.63 35 4.2 98 BULK-15eed516
9071 Bulk Product 360a1d49 Home & Garden $1,004.29 466 4.5 5 BULK-e56f0d34
9072 Bulk Product f9f3f118 Books $911.53 146 3.9 19 BULK-a743e134
9073 Bulk Product 59acdfcf Toys & Games $950.07 48 4.1 42 BULK-249e5cf9
9074 Bulk Product aa993b5d Books $779.50 495 0.1 99 BULK-e270adc1
9075 Bulk Product 266cc611 Clothing $248.93 66 3.3 49 BULK-681db211
9076 Bulk Product 7a6c18ea Toys & Games $519.89 46 3.1 56 BULK-c56c4f9e
9077 Bulk Product bbb3eb6f Books $655.68 12 1.7 47 BULK-c894efa9
9078 Bulk Product a4ae35c3 Home & Garden $929.42 258 1.3 59 BULK-4f64f7ac
9079 Bulk Product 4fc723ba Toys & Games $557.41 153 4.1 0 BULK-82e3dea5
9080 Bulk Product 1541fd64 Clothing $45.82 168 0.6 13 BULK-5a248941
9081 Bulk Product 1c3557e5 Home & Garden $548.40 474 3.4 46 BULK-28b66e82
9082 Bulk Product 56b28dfa Home & Garden $481.48 175 3.8 64 BULK-55986f21
9083 Bulk Product 9d5bbc19 Electronics $42.09 370 1.8 54 BULK-add6b1bd
9084 Bulk Product 35038145 Toys & Games $305.22 150 1.5 48 BULK-5b274ec3
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