Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

70 ms

Page Size

25

Current Page

907 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 907 Results Showing 22651 - 22675 of 24441

ID Name Category Price Stock Rating Reviews SKU
23210 Bulk Product 918dfcf2 Electronics $165.71 82 2.2 22 BULK-43232415
23211 Bulk Product 0522083f Toys & Games $859.31 457 0.8 33 BULK-a1c19690
23212 Bulk Product 17a4ff96 Clothing $770.93 499 1.3 12 BULK-095df6d7
23213 Bulk Product 20a30d0a Books $634.86 237 1.6 6 BULK-b466b077
23214 Bulk Product a497615b Electronics $331.08 445 0.9 22 BULK-b4f75dee
23215 Bulk Product f918dae7 Clothing $318.30 338 3.9 23 BULK-0039f6d1
23216 Bulk Product d43aae18 Sports & Outdoors $485.50 406 2.5 21 BULK-b70fc526
23217 Bulk Product 492de078 Books $970.17 178 4.4 69 BULK-876d30c7
23218 Bulk Product d79d1a70 Electronics $494.71 63 4.4 59 BULK-44a948f5
23219 Bulk Product 564696de Books $924.27 125 2.0 14 BULK-8f64e4cd
23220 Bulk Product 990c3187 Home & Garden $637.42 28 2.9 93 BULK-456c6174
23221 Bulk Product 899fb301 Electronics $702.31 355 0.1 50 BULK-a52d7c3f
23222 Bulk Product 9c1ea059 Home & Garden $370.43 126 2.8 79 BULK-b932ab19
23223 Bulk Product 7e40cdac Electronics $809.24 181 4.3 6 BULK-d53c338c
23224 Bulk Product 13870f9c Sports & Outdoors $158.91 404 2.7 35 BULK-fe8b21e1
23225 Bulk Product 718f9bb1 Books $27.92 331 4.4 82 BULK-0d71c964
23226 Bulk Product 5797c4ae Books $376.73 109 4.9 15 BULK-cc33f568
23227 Bulk Product bb090415 Home & Garden $702.68 265 3.3 66 BULK-d3d696d7
23228 Bulk Product 5ec19975 Books $457.56 319 3.4 34 BULK-6f0bc1d5
23229 Bulk Product bc1869e6 Toys & Games $557.63 412 2.1 55 BULK-1506e5e5
23230 Bulk Product 4df9b2f1 Sports & Outdoors $803.12 448 5.0 9 BULK-5c1b7fc9
23231 Bulk Product 2e637965 Toys & Games $801.07 325 1.0 33 BULK-1ded8893
23232 Bulk Product 07d6a44b Books $715.21 475 2.9 76 BULK-0e2291ac
23233 Bulk Product 78d54a75 Home & Garden $507.88 42 4.8 85 BULK-f9c97547
23234 Bulk Product 7305f7d5 Clothing $861.45 443 4.2 54 BULK-411a7f52
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