Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

189 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 189 Results Showing 4701 - 4725 of 24441

ID Name Category Price Stock Rating Reviews SKU
5260 Bulk Product 338641e7 Toys & Games $134.33 110 4.4 2 BULK-8bf82e7f
5261 Bulk Product 98a5c768 Clothing $745.00 208 3.2 75 BULK-876e42c5
5262 Bulk Product faf9e436 Books $923.70 348 1.5 31 BULK-4e2eb147
5263 Bulk Product 11f61d8b Books $317.60 124 2.7 28 BULK-2a13f645
5264 Bulk Product fa01f8f0 Clothing $499.07 122 0.0 77 BULK-bc1558e4
5265 Bulk Product 52c9c37b Electronics $152.14 113 3.7 58 BULK-32ca00b7
5266 Bulk Product f0bad023 Toys & Games $138.27 422 1.0 81 BULK-e15d95d8
5267 Bulk Product 05c9c995 Books $804.38 488 2.4 86 BULK-36346e23
5268 Bulk Product a11631e3 Clothing $440.14 137 1.4 22 BULK-76bd87bc
5269 Bulk Product 11d40a98 Clothing $566.10 488 1.3 32 BULK-9e8f216a
5270 Bulk Product f367ef39 Books $985.43 418 3.1 20 BULK-d68ef807
5271 Bulk Product a650c7ee Home & Garden $804.02 9 1.5 47 BULK-335c5703
5272 Bulk Product 643462c9 Home & Garden $533.50 267 1.2 36 BULK-47572d09
5273 Bulk Product de51d5c6 Home & Garden $131.60 399 0.8 10 BULK-5852fd8c
5274 Bulk Product df3d89d1 Clothing $237.25 430 1.8 42 BULK-03ad2938
5275 Bulk Product e43ffa6c Books $458.98 278 0.5 71 BULK-948b73a6
5276 Bulk Product e8cf7e8f Electronics $363.96 306 1.2 82 BULK-c424d79e
5277 Bulk Product 60c45913 Home & Garden $243.28 403 1.7 56 BULK-6094c101
5278 Bulk Product b9e758e5 Clothing $501.42 475 5.0 87 BULK-b6101639
5279 Bulk Product 492f94dc Electronics $783.12 455 0.2 5 BULK-56b11a39
5280 Bulk Product 0dd04970 Sports & Outdoors $41.04 229 4.5 58 BULK-55f53659
5281 Bulk Product 5298f0fd Books $932.54 487 4.6 3 BULK-8ae6925c
5282 Bulk Product 9ebe9c70 Electronics $434.05 447 0.6 24 BULK-46a608b9
5283 Bulk Product c6f1c2fd Home & Garden $878.10 386 1.7 71 BULK-017fb217
5284 Bulk Product 58a756c6 Electronics $304.27 205 0.1 21 BULK-f5ba95fb
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