Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

29 ms

Page Size

25

Current Page

744 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 744 Results Showing 18576 - 18600 of 24441

ID Name Category Price Stock Rating Reviews SKU
19135 Bulk Product b68b19f7 Home & Garden $605.89 146 1.6 87 BULK-7801f66f
19136 Bulk Product 0f8f450b Clothing $842.44 153 0.1 76 BULK-1594176d
19137 Bulk Product 1546486a Sports & Outdoors $429.26 378 3.5 62 BULK-901aa937
19138 Bulk Product d4690e83 Toys & Games $82.80 66 3.5 72 BULK-e77bca14
19139 Bulk Product 961cf07d Clothing $472.28 79 3.1 5 BULK-1b7adc15
19140 Bulk Product 86f29900 Books $827.62 432 0.3 19 BULK-ab7d400b
19141 Bulk Product cead7731 Books $613.94 337 0.4 86 BULK-1be76a74
19142 Bulk Product 2c1fa9af Electronics $859.78 233 2.8 20 BULK-6505e2b5
19143 Bulk Product f25d01f9 Clothing $129.37 97 3.9 79 BULK-3a0e5900
19144 Bulk Product 1b2b5515 Home & Garden $41.59 452 2.9 7 BULK-02359008
19145 Bulk Product f27ac60d Toys & Games $693.16 35 2.3 41 BULK-05c1431a
19146 Bulk Product be45a189 Books $952.82 205 4.0 73 BULK-de3de213
19147 Bulk Product d4ec9ebf Electronics $614.29 483 2.1 75 BULK-295fd3e2
19148 Bulk Product f29aee49 Clothing $338.66 483 5.0 62 BULK-eec412b6
19149 Bulk Product 4599c3fe Electronics $981.04 0 3.5 82 BULK-faeae33e
19150 Bulk Product 7b90c9d8 Electronics $194.38 190 1.8 40 BULK-83f026a3
19151 Bulk Product 9a9306dd Sports & Outdoors $681.23 29 0.6 56 BULK-cf4cc703
19152 Bulk Product 7c079965 Sports & Outdoors $366.04 121 0.4 55 BULK-1fea07aa
19153 Bulk Product 2a682415 Electronics $536.94 492 0.0 15 BULK-3196e7fe
19154 Bulk Product 64a9e071 Home & Garden $37.86 440 3.5 95 BULK-a3bc4d94
19155 Bulk Product f17b06ca Clothing $960.24 202 2.8 49 BULK-4a28bfc1
19156 Bulk Product 1cb40013 Clothing $811.90 310 4.5 74 BULK-40eed721
19157 Bulk Product 87ff01c6 Home & Garden $954.76 146 2.3 6 BULK-483f12c8
19158 Bulk Product 5c9b1359 Toys & Games $184.81 400 1.4 53 BULK-d3a40197
19159 Bulk Product 458cf914 Electronics $915.57 43 1.3 1 BULK-cd34ffe2
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