Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

51 ms

Page Size

25

Current Page

424 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 424 Results Showing 10576 - 10600 of 24441

ID Name Category Price Stock Rating Reviews SKU
11135 Bulk Product a2c7b36a Home & Garden $820.82 246 1.1 78 BULK-ae0a03fd
11136 Bulk Product 3570dc42 Electronics $101.35 399 4.9 65 BULK-a17f082a
11137 Bulk Product 81108515 Toys & Games $597.15 238 2.4 59 BULK-9348d30f
11138 Bulk Product 74234ad9 Clothing $441.45 164 4.8 94 BULK-b70996c9
11139 Bulk Product e445aead Clothing $180.62 80 3.6 11 BULK-1be1f92a
11140 Bulk Product f79670d3 Home & Garden $408.92 497 4.8 28 BULK-8952bc20
11141 Bulk Product 1b8acead Sports & Outdoors $844.20 64 1.0 96 BULK-cb81a328
11142 Bulk Product 42f29c7c Clothing $499.26 126 3.0 37 BULK-22cf9ca1
11143 Bulk Product 513eaf71 Electronics $914.86 335 2.7 6 BULK-b4be2e10
11144 Bulk Product 744f85d5 Toys & Games $758.02 213 3.1 10 BULK-818228ac
11145 Bulk Product 2c02fc9e Electronics $252.28 406 2.6 24 BULK-cb924862
11146 Bulk Product 236275ce Toys & Games $919.49 310 1.2 83 BULK-f1bbfdc3
11147 Bulk Product 73eca608 Home & Garden $574.75 445 4.6 49 BULK-e6ff2f2b
11148 Bulk Product e869d467 Sports & Outdoors $280.97 259 4.1 44 BULK-ecb25062
11149 Bulk Product 0ee1978f Electronics $412.92 303 1.8 9 BULK-d06b9881
11150 Bulk Product cd727bdb Electronics $432.58 57 3.7 50 BULK-749d5f87
11151 Bulk Product 99cc0158 Toys & Games $1,005.69 396 1.8 19 BULK-7ecbaedd
11152 Bulk Product 9f024054 Books $539.94 244 2.8 49 BULK-d242943c
11153 Bulk Product d5bb640c Home & Garden $643.88 400 1.5 28 BULK-38f1db34
11154 Bulk Product 2a42dcda Books $549.31 454 2.3 29 BULK-434d7f7e
11155 Bulk Product a2609f66 Electronics $905.91 6 1.4 62 BULK-e12f651f
11156 Bulk Product 1171290a Sports & Outdoors $420.73 14 2.9 58 BULK-29307a2b
11157 Bulk Product 0cf28370 Books $1,007.57 12 2.2 67 BULK-dcf405f0
11158 Bulk Product 9408bc8b Sports & Outdoors $472.03 365 3.8 18 BULK-b17f4ce4
11159 Bulk Product 94c585c8 Books $1,007.45 89 3.4 38 BULK-60996c12
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