Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

33 ms

Page Size

25

Current Page

211 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 211 Results Showing 5251 - 5275 of 24441

ID Name Category Price Stock Rating Reviews SKU
5810 Bulk Product 852f14c4 Home & Garden $656.67 118 3.0 39 BULK-49085a3f
5811 Bulk Product ce66dd91 Sports & Outdoors $911.14 176 2.3 2 BULK-625cf392
5812 Bulk Product 09c40657 Toys & Games $685.25 255 3.2 86 BULK-522d7991
5813 Bulk Product 8160ab0b Electronics $659.01 140 3.6 13 BULK-bf3956d2
5814 Bulk Product 1c240633 Clothing $576.40 384 2.0 11 BULK-fdbe5ead
5815 Bulk Product 55561952 Clothing $518.00 57 0.1 99 BULK-995338dd
5816 Bulk Product 4b8eef9c Toys & Games $735.69 77 2.9 56 BULK-18b20ae2
5817 Bulk Product f827c005 Toys & Games $578.38 458 1.2 84 BULK-517dbdbd
5818 Bulk Product 16fc30bc Electronics $893.78 20 0.4 55 BULK-0321ce4e
5819 Bulk Product a21b65fc Toys & Games $138.64 62 0.1 83 BULK-9a4ce143
5820 Bulk Product 6b18b17b Clothing $66.88 496 0.6 64 BULK-675c1829
5821 Bulk Product 344a9fcb Electronics $531.00 98 4.4 66 BULK-4b58ad28
5822 Bulk Product 95b9221b Books $308.34 475 3.0 49 BULK-003ccdb1
5823 Bulk Product 0675baa4 Electronics $371.45 358 4.4 24 BULK-435b5a1c
5824 Bulk Product ee10c58e Books $910.89 264 3.5 74 BULK-14598631
5825 Bulk Product 119c0a1b Books $747.45 101 1.0 42 BULK-630f6252
5826 Bulk Product 0b35a5fb Home & Garden $587.66 199 3.3 34 BULK-0651b6e3
5827 Bulk Product dd155f69 Clothing $168.61 403 2.9 50 BULK-02c98ead
5828 Bulk Product aaf250ac Clothing $420.46 335 4.8 11 BULK-4d7e5fa6
5829 Bulk Product 915626f6 Clothing $952.06 3 1.5 87 BULK-701360f1
5830 Bulk Product b8a9f1bb Clothing $726.31 99 2.1 43 BULK-df7c67fb
5831 Bulk Product 61beb19d Home & Garden $709.60 17 0.6 74 BULK-f808fe46
5832 Bulk Product 22b5557d Electronics $146.56 197 4.2 34 BULK-5bd77287
5833 Bulk Product bae82e5b Electronics $917.92 386 3.1 16 BULK-d7c9b36d
5834 Bulk Product fcf94220 Home & Garden $260.81 445 0.4 33 BULK-9a23842e
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