Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

1910 ms

Page Size

25

Current Page

312 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 312 Results Showing 7776 - 7800 of 24441

ID Name Category Price Stock Rating Reviews SKU
8335 Bulk Product 6ce9c9b0 Electronics $651.74 330 3.0 41 BULK-25d1d9f2
8336 Bulk Product 321084de Home & Garden $700.44 31 0.2 87 BULK-d1724a54
8337 Bulk Product ab3dd97c Electronics $316.08 261 1.2 43 BULK-8221d508
8338 Bulk Product 2288d45d Sports & Outdoors $637.11 249 1.8 79 BULK-85b333dd
8339 Bulk Product 5d87e0dd Books $962.52 121 2.0 41 BULK-c8aaeb6a
8340 Bulk Product 92464501 Sports & Outdoors $844.69 401 1.4 97 BULK-127ef2e3
8341 Bulk Product 15611e4c Clothing $195.89 451 4.0 49 BULK-40abc432
8342 Bulk Product c494fbda Toys & Games $923.51 37 4.7 29 BULK-6403093a
8343 Bulk Product c7e6e8e2 Clothing $25.53 176 0.2 31 BULK-f013339b
8344 Bulk Product d640ad91 Toys & Games $215.16 496 4.0 60 BULK-862783db
8345 Bulk Product 808dda99 Electronics $79.49 152 3.2 94 BULK-56d95d1f
8346 Bulk Product ad460625 Books $243.13 219 2.3 61 BULK-74ac0dd7
8347 Bulk Product 0f8ea7cb Clothing $886.10 226 4.8 54 BULK-93d6bd03
8348 Bulk Product aeb57c7d Electronics $721.61 89 2.3 76 BULK-c722d776
8349 Bulk Product 79614152 Home & Garden $519.46 363 2.3 40 BULK-7f41034e
8350 Bulk Product 2ac4fc85 Sports & Outdoors $938.94 263 5.0 55 BULK-1d144272
8351 Bulk Product 53bd72b8 Home & Garden $268.42 120 1.7 73 BULK-dc0d70cb
8352 Bulk Product 12730a7b Books $708.22 441 2.0 31 BULK-87c8f602
8353 Bulk Product 825b4947 Toys & Games $159.91 185 0.3 37 BULK-1f7ab787
8354 Bulk Product b18dc71f Toys & Games $534.96 15 1.5 75 BULK-bb8ae906
8355 Bulk Product 677d3fdb Books $683.75 326 3.7 93 BULK-fc67c9a6
8356 Bulk Product 4ebbbf76 Sports & Outdoors $766.87 432 1.7 49 BULK-9deac593
8357 Bulk Product 747f44fe Home & Garden $968.75 493 1.7 80 BULK-5a0152f2
8358 Bulk Product 98012d69 Clothing $815.03 224 2.2 33 BULK-e8e370b2
8359 Bulk Product c20aa04c Electronics $725.87 362 3.7 73 BULK-606754f4
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