Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

25

Current Page

348 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 348 Results Showing 8676 - 8700 of 24441

ID Name Category Price Stock Rating Reviews SKU
9235 Bulk Product 5780b776 Toys & Games $390.38 452 0.7 14 BULK-89b9dffc
9236 Bulk Product 7052e3d9 Toys & Games $549.10 239 0.2 99 BULK-0977bc1b
9237 Bulk Product a75e49a4 Toys & Games $672.68 272 1.6 90 BULK-b5856459
9238 Bulk Product 078dd17e Home & Garden $983.02 32 3.5 24 BULK-1b992182
9239 Bulk Product 4917ff34 Sports & Outdoors $592.09 51 0.0 51 BULK-45ce7776
9240 Bulk Product 868c9d47 Toys & Games $992.40 133 4.3 48 BULK-c9f6cbec
9241 Bulk Product 399a85d0 Toys & Games $391.43 359 0.7 31 BULK-7f686338
9242 Bulk Product 050f7fe1 Home & Garden $778.61 6 3.3 71 BULK-8b2dca7d
9243 Bulk Product 5f376283 Toys & Games $464.44 397 2.1 22 BULK-fc049df9
9244 Bulk Product a5e5e38c Books $862.63 201 3.9 95 BULK-a121c9e7
9245 Bulk Product f91ffc64 Electronics $353.54 443 4.4 32 BULK-cac64768
9246 Bulk Product a0eaba45 Clothing $122.40 450 3.4 83 BULK-5c6f63a6
9247 Bulk Product 39d6970f Home & Garden $452.08 314 3.7 0 BULK-1245c8ab
9248 Bulk Product b25ba773 Toys & Games $150.69 474 3.6 54 BULK-c0a056e3
9249 Bulk Product 12d40ffb Toys & Games $409.41 43 0.5 26 BULK-7ab3d4e5
9250 Bulk Product d33236e3 Electronics $480.34 56 1.7 91 BULK-5caef956
9251 Bulk Product f8191f97 Electronics $227.95 123 5.0 31 BULK-27120ca0
9252 Bulk Product d475d5fb Clothing $866.15 41 1.3 59 BULK-6cd3aa7e
9253 Bulk Product 8f36aee6 Sports & Outdoors $875.01 408 1.6 88 BULK-1448762d
9254 Bulk Product 643487b5 Toys & Games $489.67 9 2.7 65 BULK-75800443
9255 Bulk Product 33afcc83 Electronics $791.16 321 3.0 2 BULK-2fd90c56
9256 Bulk Product 1ef46798 Sports & Outdoors $483.86 19 4.2 59 BULK-82fa2acc
9257 Bulk Product af0bcdfd Clothing $936.01 204 4.7 67 BULK-783be742
9258 Bulk Product b01ad598 Toys & Games $418.27 473 1.9 22 BULK-3fb59bfd
9259 Bulk Product e6ea9ddc Sports & Outdoors $153.89 60 1.5 1 BULK-eefdbef8
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