Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

25

Current Page

909 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 909 Results Showing 22701 - 22725 of 24441

ID Name Category Price Stock Rating Reviews SKU
23260 Bulk Product a93e4162 Sports & Outdoors $952.57 45 0.8 76 BULK-49c83814
23261 Bulk Product 6113a674 Books $956.65 328 3.6 90 BULK-45768a70
23262 Bulk Product 28f3fcd9 Electronics $423.43 302 3.5 36 BULK-6a3a1a9e
23263 Bulk Product fd699cf2 Books $241.33 414 4.4 38 BULK-d6701b1a
23264 Bulk Product 9a3fdd5d Books $926.56 249 2.2 8 BULK-29a1dc66
23265 Bulk Product 3fbe4d38 Sports & Outdoors $235.56 201 4.7 16 BULK-4d8fee07
23266 Bulk Product 4dc847eb Sports & Outdoors $426.06 203 1.5 6 BULK-325cc041
23267 Bulk Product 67a176c9 Clothing $509.81 147 3.1 92 BULK-221efba5
23268 Bulk Product 724fa626 Home & Garden $902.51 369 1.0 13 BULK-21287613
23269 Bulk Product 0e7b1583 Books $769.79 159 2.1 84 BULK-386f3b8f
23270 Bulk Product 864cfa0d Books $62.21 152 0.0 78 BULK-04227bef
23271 Bulk Product d2add85b Toys & Games $969.69 419 1.4 71 BULK-adb1fc88
23272 Bulk Product 98d13188 Electronics $604.18 499 4.4 63 BULK-316c6dea
23273 Bulk Product 99f2bc7f Toys & Games $737.85 483 2.5 80 BULK-d289d67e
23274 Bulk Product 0c68d5ef Home & Garden $243.04 51 1.3 47 BULK-4b537923
23275 Bulk Product d8689c72 Sports & Outdoors $34.46 285 4.0 53 BULK-4faa1707
23276 Bulk Product 7892225f Toys & Games $786.45 137 4.9 95 BULK-68a9f965
23277 Bulk Product 186dc404 Sports & Outdoors $708.37 254 0.7 56 BULK-2e9f62ee
23278 Bulk Product 725cb5ea Home & Garden $798.95 138 4.6 42 BULK-62af7c89
23279 Bulk Product 0c1e346d Home & Garden $386.00 18 1.4 10 BULK-d64a4e34
23280 Bulk Product 39b233ac Home & Garden $301.61 343 1.5 83 BULK-e3abe5f2
23281 Bulk Product b0eb82eb Sports & Outdoors $734.81 150 5.0 4 BULK-bb719462
23282 Bulk Product b2f1b418 Clothing $222.32 295 2.2 8 BULK-1a73ea6d
23283 Bulk Product bcfb7d05 Sports & Outdoors $783.28 184 0.7 63 BULK-c38ec300
23284 Bulk Product 04f78a4d Electronics $641.99 144 2.6 18 BULK-53a8b8e4
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