Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

961 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 961 Results Showing 24001 - 24025 of 24441

ID Name Category Price Stock Rating Reviews SKU
24560 Bulk Product 3716c0af Clothing $951.22 219 0.4 42 BULK-30b6a92c
24561 Bulk Product 0a9af138 Home & Garden $478.58 228 2.6 54 BULK-1c5785e5
24562 Bulk Product b51da0d6 Sports & Outdoors $535.42 305 0.3 82 BULK-d9834c90
24563 Bulk Product c3bfcaa7 Electronics $133.20 171 1.0 39 BULK-60d4ca51
24564 Bulk Product 5c156f25 Home & Garden $398.04 53 0.8 71 BULK-f07ec94e
24565 Bulk Product 02242e59 Home & Garden $300.62 322 4.8 68 BULK-46b85af5
24566 Bulk Product a80f9c49 Toys & Games $110.46 367 4.3 36 BULK-404a664e
24567 Bulk Product 75dd9973 Home & Garden $879.07 313 2.6 16 BULK-53bbda79
24568 Bulk Product fa845c0d Home & Garden $718.46 452 2.3 83 BULK-b1cee31c
24569 Bulk Product d3985827 Books $301.86 34 2.3 69 BULK-b7b2f472
24570 Bulk Product 60f0356f Books $14.84 223 1.6 73 BULK-00a52ab6
24571 Bulk Product 674fc516 Books $602.65 323 2.4 38 BULK-e1a55636
24572 Bulk Product 4a53d9f8 Books $540.35 21 0.9 4 BULK-8ecdcf22
24573 Bulk Product 4bcb6a09 Sports & Outdoors $449.17 359 4.5 90 BULK-6870f344
24574 Bulk Product e1048dcb Sports & Outdoors $157.10 203 3.7 57 BULK-e46fc905
24575 Bulk Product 06bc9bd0 Toys & Games $574.34 117 4.1 83 BULK-7092ad18
24576 Bulk Product 53e24113 Books $193.87 82 3.2 11 BULK-aca94324
24577 Bulk Product 3132a9f2 Home & Garden $374.94 23 0.5 61 BULK-dc78f365
24578 Bulk Product a2a47dd0 Home & Garden $58.97 128 4.0 67 BULK-e5b5268d
24579 Bulk Product 06336cb2 Electronics $373.39 424 3.6 5 BULK-a091a382
24580 Bulk Product 6a72c32f Electronics $106.18 438 2.2 45 BULK-45985196
24581 Bulk Product 5edc63a2 Toys & Games $748.61 192 1.7 59 BULK-97f7fdc2
24582 Bulk Product dcb10d48 Home & Garden $623.07 76 1.3 25 BULK-ecc67d18
24583 Bulk Product 931aa349 Sports & Outdoors $747.48 423 0.9 99 BULK-27bb2734
24584 Bulk Product 6c3b8064 Sports & Outdoors $839.23 479 1.7 21 BULK-4ab6c13d
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