Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

749 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 749 Results Showing 18701 - 18725 of 24441

ID Name Category Price Stock Rating Reviews SKU
19260 Bulk Product 334df25b Home & Garden $297.00 324 2.5 30 BULK-2760a47b
19261 Bulk Product 1e4db950 Clothing $188.33 13 1.5 42 BULK-920e37d3
19262 Bulk Product 574cd9cf Sports & Outdoors $243.64 117 3.4 30 BULK-3f9fdbf7
19263 Bulk Product 0d1fd937 Electronics $389.30 449 4.5 69 BULK-a474ffeb
19264 Bulk Product a586349e Sports & Outdoors $894.41 365 0.8 4 BULK-f13cc751
19265 Bulk Product b4d4711e Sports & Outdoors $215.63 427 3.6 98 BULK-88ccffb9
19266 Bulk Product c0339fb8 Clothing $546.96 164 1.5 33 BULK-76d51b06
19267 Bulk Product db95b326 Electronics $590.50 167 0.5 5 BULK-66949ce2
19268 Bulk Product 5330f16a Toys & Games $626.75 292 0.7 26 BULK-01405833
19269 Bulk Product 0adf6035 Books $785.74 360 3.3 62 BULK-a616d148
19270 Bulk Product 2f568d03 Electronics $934.89 28 4.1 78 BULK-ae9643dc
19271 Bulk Product da7a49d7 Books $119.70 264 1.7 35 BULK-28cc1198
19272 Bulk Product 246ee158 Sports & Outdoors $246.43 108 0.6 2 BULK-4911df2d
19273 Bulk Product 8a92cd84 Home & Garden $155.21 250 0.9 25 BULK-198aeb8c
19274 Bulk Product 709848e3 Home & Garden $44.47 83 2.7 17 BULK-a775956a
19275 Bulk Product fc40fb7f Toys & Games $908.97 478 4.8 58 BULK-f614992c
19276 Bulk Product ed7bfff8 Clothing $435.92 172 1.2 42 BULK-ea913141
19277 Bulk Product 42279e16 Toys & Games $350.14 385 2.4 8 BULK-ff8e935b
19278 Bulk Product ab93ee2e Electronics $749.29 343 4.4 86 BULK-ab015641
19279 Bulk Product 2df6e88c Clothing $584.16 18 2.4 30 BULK-85cc9414
19280 Bulk Product 2cc1b6c4 Toys & Games $824.70 213 0.9 31 BULK-69600d5f
19281 Bulk Product bfdbb232 Sports & Outdoors $399.90 397 4.3 7 BULK-1fdfb7a3
19282 Bulk Product c2f67c30 Clothing $456.35 21 3.4 82 BULK-8d9a275c
19283 Bulk Product ab2d9f18 Books $417.09 467 1.0 40 BULK-8d2a166d
19284 Bulk Product 65cec129 Toys & Games $63.27 211 2.6 52 BULK-684ccaa9
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