Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

10 ms

Page Size

25

Current Page

311 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 311 Results Showing 7751 - 7775 of 24441

ID Name Category Price Stock Rating Reviews SKU
8310 Bulk Product c5929a25 Books $380.83 475 0.4 86 BULK-2a430678
8311 Bulk Product 121edb5e Home & Garden $636.57 183 3.6 41 BULK-8c25ace5
8312 Bulk Product a23a7b3f Home & Garden $547.79 141 3.7 30 BULK-c38073e1
8313 Bulk Product 62b2a10d Electronics $156.09 439 1.0 22 BULK-8aa4a62b
8314 Bulk Product 56ad514d Electronics $477.28 344 1.9 44 BULK-d87222d2
8315 Bulk Product 30cbd06f Home & Garden $734.01 130 1.5 71 BULK-fb93284b
8316 Bulk Product 1f14fe7e Clothing $543.07 234 4.8 14 BULK-a91ce857
8317 Bulk Product 4b0fa2ed Home & Garden $737.39 85 0.0 44 BULK-a0c778c3
8318 Bulk Product f52ed887 Electronics $942.69 253 0.8 44 BULK-3271c249
8319 Bulk Product b10063be Sports & Outdoors $387.78 103 3.6 89 BULK-6639c482
8320 Bulk Product 2c542668 Books $304.68 67 0.5 51 BULK-3d3ed6dc
8321 Bulk Product 4d6ec2ef Electronics $503.22 395 2.5 60 BULK-90dc7e56
8322 Bulk Product 63ef7211 Electronics $469.50 353 1.0 87 BULK-5642c8c4
8323 Bulk Product 53dfb8d8 Books $871.98 57 1.8 79 BULK-447ac6ca
8324 Bulk Product 1df651a5 Sports & Outdoors $675.94 46 1.7 74 BULK-44dc6e55
8325 Bulk Product cc53ff0f Clothing $601.16 395 4.5 34 BULK-dba14919
8326 Bulk Product d717f519 Home & Garden $385.86 474 4.1 57 BULK-5f80d60a
8327 Bulk Product a5922dbd Home & Garden $12.91 313 3.0 52 BULK-ee85ae65
8328 Bulk Product 0983c7cc Home & Garden $698.14 202 0.8 78 BULK-cb32fb3f
8329 Bulk Product 0f5b953c Books $915.28 337 0.8 90 BULK-deb569c0
8330 Bulk Product 77fe8d98 Clothing $800.25 21 3.2 29 BULK-5284fc55
8331 Bulk Product 20d9b657 Toys & Games $127.35 41 3.5 43 BULK-ffe388da
8332 Bulk Product e749666c Toys & Games $808.41 329 4.4 7 BULK-0981b3c7
8333 Bulk Product 6f91129e Books $196.73 166 0.2 95 BULK-46fc8d98
8334 Bulk Product e27b9b4a Toys & Games $996.79 278 0.8 18 BULK-f675b7ce
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