Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

468 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 468 Results Showing 11676 - 11700 of 24441

ID Name Category Price Stock Rating Reviews SKU
12235 Bulk Product 1f7589a9 Home & Garden $34.39 435 3.6 29 BULK-4e7d8f95
12236 Bulk Product 5e982dc8 Clothing $571.65 416 4.4 46 BULK-f52f7c34
12237 Bulk Product 6e5bf845 Home & Garden $816.55 330 2.0 95 BULK-76f7a73b
12238 Bulk Product a5e53a2c Clothing $68.25 376 0.0 62 BULK-1b1da821
12239 Bulk Product 4b304096 Sports & Outdoors $883.76 336 0.2 44 BULK-0656d84a
12240 Bulk Product e870653a Books $188.32 425 1.7 2 BULK-fd5b7804
12241 Bulk Product 8b2a5779 Sports & Outdoors $609.23 111 2.6 47 BULK-723489e1
12242 Bulk Product bc55b445 Home & Garden $583.67 28 0.6 62 BULK-4a7117ff
12243 Bulk Product bee3475a Electronics $24.22 249 5.0 70 BULK-1203810d
12244 Bulk Product e1a7f8a5 Toys & Games $810.14 157 4.6 8 BULK-7a168363
12245 Bulk Product f7044fa8 Clothing $804.45 134 1.0 23 BULK-ae36d96e
12246 Bulk Product 79a6be5e Home & Garden $224.43 216 0.3 87 BULK-917dc518
12247 Bulk Product fea33a42 Electronics $381.64 373 1.9 27 BULK-b463d4e8
12248 Bulk Product 14548f3e Home & Garden $980.12 494 3.1 76 BULK-fe29c348
12249 Bulk Product 4455af9a Toys & Games $509.99 411 0.1 81 BULK-169c5e12
12250 Bulk Product a6ef931c Toys & Games $495.88 160 1.8 25 BULK-813cfb5e
12251 Bulk Product 08b26e3b Home & Garden $776.57 90 1.6 94 BULK-f893d982
12252 Bulk Product 33096c9c Home & Garden $480.30 281 0.6 73 BULK-9ec47bb7
12253 Bulk Product c77c2e8c Sports & Outdoors $584.67 43 0.0 56 BULK-0e86950d
12254 Bulk Product 06b272f5 Home & Garden $400.07 57 2.9 96 BULK-313e0591
12255 Bulk Product 477e3bc7 Books $120.56 261 4.4 10 BULK-f7eebd32
12256 Bulk Product c741937c Toys & Games $873.07 56 3.5 74 BULK-b626cf2f
12257 Bulk Product 68ccc1dd Clothing $581.39 1 0.8 20 BULK-6693dfd2
12258 Bulk Product 188d4d81 Electronics $996.06 220 0.6 73 BULK-cff6ded6
12259 Bulk Product ec54050a Home & Garden $824.63 113 2.5 54 BULK-b9bb5c72
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