Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

490 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 490 Results Showing 12226 - 12250 of 24441

ID Name Category Price Stock Rating Reviews SKU
12785 Bulk Product 50afe8a5 Sports & Outdoors $158.98 163 1.7 59 BULK-96aeb7f7
12786 Bulk Product 38c57ca4 Books $761.69 408 0.1 52 BULK-a9def626
12787 Bulk Product f4099c8a Home & Garden $76.68 404 4.8 0 BULK-cd5fd778
12788 Bulk Product cf1da32e Books $83.43 98 0.6 81 BULK-562569d8
12789 Bulk Product 290dfbfb Home & Garden $127.77 174 1.6 51 BULK-95b7f13c
12790 Bulk Product 63628a17 Clothing $220.39 392 1.6 20 BULK-52ea2983
12791 Bulk Product 0139305b Home & Garden $962.70 276 3.2 14 BULK-83488ead
12792 Bulk Product 9d5fd9fe Toys & Games $940.56 21 4.2 52 BULK-67f8df62
12793 Bulk Product 80473618 Home & Garden $535.12 363 2.7 24 BULK-6eabda68
12794 Bulk Product 20abff88 Books $779.55 494 1.3 70 BULK-8bb06d18
12795 Bulk Product c4b098c0 Sports & Outdoors $621.65 286 4.2 73 BULK-320ab479
12796 Bulk Product a1390e14 Home & Garden $511.90 94 0.0 67 BULK-62dc424e
12797 Bulk Product af009e89 Books $151.29 132 0.5 91 BULK-becf5988
12798 Bulk Product 057415ba Sports & Outdoors $951.18 382 1.7 86 BULK-de7918e1
12799 Bulk Product fdae9a00 Sports & Outdoors $324.08 323 2.5 16 BULK-8e0bca4f
12800 Bulk Product 5d913111 Sports & Outdoors $579.91 393 0.8 60 BULK-8a0d99c9
12801 Bulk Product 1d40900e Home & Garden $465.03 25 0.7 99 BULK-b747149c
12802 Bulk Product 93c4ae86 Books $661.97 267 3.2 56 BULK-44f5ea46
12803 Bulk Product 246e6d70 Clothing $802.86 71 1.9 56 BULK-3ea61340
12804 Bulk Product b7d7806a Sports & Outdoors $70.91 363 4.5 90 BULK-eb544ade
12805 Bulk Product fabdacd6 Clothing $893.26 222 1.9 14 BULK-55762d83
12806 Bulk Product 05152daa Electronics $328.57 37 0.4 35 BULK-bdeedc2c
12807 Bulk Product 16946a0d Toys & Games $997.02 169 2.0 0 BULK-9f81298a
12808 Bulk Product a3e750cd Sports & Outdoors $498.04 486 2.3 0 BULK-bc0efdbc
12809 Bulk Product c4d62419 Electronics $728.43 415 1.0 3 BULK-770539b4
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