Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

259 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 259 Results Showing 6451 - 6475 of 24441

ID Name Category Price Stock Rating Reviews SKU
7010 Bulk Product 86c17bc5 Toys & Games $574.29 370 4.8 18 BULK-f581d3ee
7011 Bulk Product b616fcab Sports & Outdoors $910.79 484 0.0 25 BULK-a3db3626
7012 Bulk Product d922704b Sports & Outdoors $72.25 76 3.7 80 BULK-f0646268
7013 Bulk Product 6302d26a Sports & Outdoors $322.15 427 0.4 1 BULK-d41932e2
7014 Bulk Product 060208ab Home & Garden $763.47 424 2.3 45 BULK-ffc1a5a0
7015 Bulk Product 3fda7c72 Toys & Games $542.63 117 4.1 81 BULK-6633f61e
7016 Bulk Product 949c03e8 Toys & Games $22.03 36 0.7 97 BULK-a44fecf8
7017 Bulk Product d81b8b3a Electronics $399.63 6 3.9 68 BULK-cee0dfae
7018 Bulk Product 2c1f1bc0 Home & Garden $735.02 405 3.0 62 BULK-be387258
7019 Bulk Product 4b9f04ff Clothing $157.81 248 2.4 48 BULK-d03d84e4
7020 Bulk Product e13d71b8 Sports & Outdoors $30.12 342 2.9 58 BULK-36840425
7021 Bulk Product 89c33c40 Electronics $632.29 80 2.2 22 BULK-f3d41226
7022 Bulk Product ac35a1e0 Home & Garden $212.50 127 4.8 12 BULK-92c365e2
7023 Bulk Product d930a694 Clothing $727.18 324 2.5 62 BULK-84981d8d
7024 Bulk Product 854a2f69 Sports & Outdoors $478.98 15 0.6 37 BULK-c409a243
7025 Bulk Product dcaffdba Electronics $238.90 198 1.9 40 BULK-27273534
7026 Bulk Product 5a8b4b17 Books $711.31 38 0.4 66 BULK-d7e884b1
7027 Bulk Product d74c1969 Books $498.58 284 4.9 99 BULK-14f55f1d
7028 Bulk Product 0d8c8a58 Clothing $476.43 329 3.4 14 BULK-e480bfb1
7029 Bulk Product ceeeb8a0 Toys & Games $428.86 453 4.0 89 BULK-d261553e
7030 Bulk Product 37a7da1c Books $892.87 200 3.8 29 BULK-7c292a70
7031 Bulk Product 356c8b64 Home & Garden $860.31 306 0.2 92 BULK-558bbb44
7032 Bulk Product 6bfa8f93 Clothing $342.81 464 1.0 85 BULK-e2b14c65
7033 Bulk Product 75b2bbe4 Books $443.99 305 2.1 17 BULK-8eda79d4
7034 Bulk Product 4da59218 Electronics $626.96 157 3.9 70 BULK-88ef0985
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