Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

1638 ms

Page Size

25

Current Page

220 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 220 Results Showing 5476 - 5500 of 24441

ID Name Category Price Stock Rating Reviews SKU
6035 Bulk Product 87df2053 Electronics $895.01 4 1.3 67 BULK-5ffd10fb
6036 Bulk Product 854e3140 Home & Garden $264.60 72 0.3 25 BULK-80a2dfb2
6037 Bulk Product 846beb03 Sports & Outdoors $441.99 73 0.8 81 BULK-4c751067
6038 Bulk Product 6c5f8e8a Books $662.24 227 4.7 63 BULK-e3b7f808
6039 Bulk Product 39b9f543 Sports & Outdoors $295.42 330 1.3 93 BULK-f8ffbf38
6040 Bulk Product 8094ee94 Home & Garden $707.57 228 0.7 68 BULK-39555171
6041 Bulk Product 376cff58 Books $727.20 327 0.3 48 BULK-1be7c1f3
6042 Bulk Product 9e068d5f Sports & Outdoors $280.89 216 2.1 87 BULK-46ac4709
6043 Bulk Product d88c1ff5 Clothing $276.69 458 0.8 90 BULK-5e5865ef
6044 Bulk Product 13a58084 Toys & Games $628.63 207 1.6 50 BULK-d4825b67
6045 Bulk Product a3f9422e Electronics $299.39 38 2.1 38 BULK-a57b5864
6046 Bulk Product 25483cad Sports & Outdoors $927.38 452 1.7 6 BULK-fe7cf7b8
6047 Bulk Product ed7f9324 Books $611.68 110 2.9 92 BULK-7f5c43e4
6048 Bulk Product e1767f43 Home & Garden $163.14 448 3.2 37 BULK-8e3d71af
6049 Bulk Product 4c0f5673 Home & Garden $212.05 498 3.2 15 BULK-f995d497
6050 Bulk Product 52646eb7 Books $206.65 97 2.3 27 BULK-37087624
6051 Bulk Product bf6f71e4 Home & Garden $499.88 66 0.7 13 BULK-1396345a
6052 Bulk Product f6a2ea44 Home & Garden $215.43 140 0.3 15 BULK-eac888b8
6053 Bulk Product 05b7af85 Clothing $205.38 187 0.9 45 BULK-b74889c2
6054 Bulk Product 8f76b0f9 Toys & Games $400.37 200 1.6 65 BULK-67bb3d0f
6055 Bulk Product 7fc7aed1 Sports & Outdoors $624.38 365 3.3 93 BULK-95132120
6056 Bulk Product f302ebe1 Electronics $549.12 95 4.4 94 BULK-25309de4
6057 Bulk Product 8fefeb6c Home & Garden $816.29 472 1.2 87 BULK-35e6dab0
6058 Bulk Product 1189f512 Sports & Outdoors $393.61 12 2.6 94 BULK-6a6ae5cf
6059 Bulk Product 94eba17e Clothing $646.21 50 2.4 26 BULK-a27f1d37
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