Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

108 ms

Page Size

25

Current Page

232 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 232 Results Showing 5776 - 5800 of 24441

ID Name Category Price Stock Rating Reviews SKU
6335 Bulk Product 5d0cbf13 Electronics $46.88 489 4.5 46 BULK-b20cd65e
6336 Bulk Product eb881b29 Electronics $945.72 455 0.2 74 BULK-a9ad5809
6337 Bulk Product 4618e6aa Electronics $464.41 461 1.6 85 BULK-3fb79565
6338 Bulk Product a4d85be8 Clothing $262.63 242 2.8 94 BULK-fb42f42d
6339 Bulk Product 91979972 Home & Garden $856.23 367 3.6 68 BULK-600550b1
6340 Bulk Product 0f63949c Home & Garden $941.05 282 2.9 91 BULK-3e896d56
6341 Bulk Product e8c29131 Clothing $79.88 366 1.9 91 BULK-9d69c384
6342 Bulk Product ae11d17b Toys & Games $904.87 114 1.9 23 BULK-08c4f378
6343 Bulk Product 75675b48 Toys & Games $742.88 406 1.3 49 BULK-bae2862a
6344 Bulk Product a4cb4c8e Electronics $982.42 124 4.5 84 BULK-047cec65
6345 Bulk Product c899e6d6 Books $110.74 99 1.7 15 BULK-739d7fcc
6346 Bulk Product bd328323 Sports & Outdoors $758.38 253 3.5 54 BULK-3b4c26fb
6347 Bulk Product 46569374 Electronics $834.34 300 4.8 56 BULK-41e12abd
6348 Bulk Product c59e6205 Sports & Outdoors $583.46 67 4.2 51 BULK-fed096c6
6349 Bulk Product f0ec5b77 Clothing $76.14 72 3.8 6 BULK-efdf351c
6350 Bulk Product d968e33e Home & Garden $136.28 118 2.1 96 BULK-979df356
6351 Bulk Product c28cf59c Clothing $547.95 17 3.3 83 BULK-14039d67
6352 Bulk Product 3ffebda5 Books $812.18 478 1.6 86 BULK-f4ac9cda
6353 Bulk Product f03a05b1 Clothing $999.42 497 4.1 74 BULK-dbc53312
6354 Bulk Product d8638640 Electronics $522.96 202 0.9 99 BULK-410d35fe
6355 Bulk Product 9b87f506 Home & Garden $201.36 236 0.7 81 BULK-314c1c5b
6356 Bulk Product dd23c9a9 Sports & Outdoors $293.49 133 4.5 90 BULK-59192603
6357 Bulk Product e3db537c Toys & Games $618.22 490 4.4 92 BULK-bab25b32
6358 Bulk Product a8196e78 Electronics $971.97 245 3.4 61 BULK-41e842a6
6359 Bulk Product f24ceec3 Toys & Games $891.16 460 0.9 81 BULK-8067cb01
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