Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

73 ms

Page Size

25

Current Page

851 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 851 Results Showing 21251 - 21275 of 24441

ID Name Category Price Stock Rating Reviews SKU
21810 Bulk Product afb97683 Toys & Games $48.78 318 4.0 59 BULK-91953aa0
21811 Bulk Product edf30d1f Home & Garden $13.81 207 3.0 96 BULK-4b3d9aba
21812 Bulk Product 7d15d19f Electronics $715.95 431 4.2 25 BULK-1f0e0712
21813 Bulk Product a0f9fffd Toys & Games $580.36 307 1.5 22 BULK-acd85a9a
21814 Bulk Product dbaaf429 Sports & Outdoors $387.28 299 1.1 42 BULK-ea7bd4cc
21815 Bulk Product 729aff5d Books $547.50 433 1.1 97 BULK-7bdb2ae1
21816 Bulk Product c610600a Clothing $224.55 405 0.2 97 BULK-0bacddbd
21817 Bulk Product 537b65f5 Sports & Outdoors $162.40 322 3.5 7 BULK-1cb1c461
21818 Bulk Product c328b89d Clothing $342.81 372 2.4 91 BULK-d701471d
21819 Bulk Product d4486093 Toys & Games $318.12 419 0.6 81 BULK-96202c50
21820 Bulk Product 6eb24ff7 Electronics $847.95 114 3.2 50 BULK-77985730
21821 Bulk Product 978cbfc9 Toys & Games $267.78 251 4.9 71 BULK-91bb883d
21822 Bulk Product a91ed610 Toys & Games $744.30 98 4.6 66 BULK-66eb7f17
21823 Bulk Product f6107d7c Books $395.94 443 0.9 85 BULK-898f8992
21824 Bulk Product 43737344 Clothing $717.29 496 3.5 98 BULK-10c422a7
21825 Bulk Product 6f51e5c6 Electronics $184.53 395 0.5 33 BULK-6d847992
21826 Bulk Product 5c961115 Home & Garden $959.16 58 2.4 67 BULK-5b801f11
21827 Bulk Product 38d1db70 Toys & Games $985.26 23 1.4 6 BULK-492a7780
21828 Bulk Product 68eea6e8 Electronics $744.63 210 4.6 22 BULK-c6081ce2
21829 Bulk Product 6767fd53 Sports & Outdoors $111.07 49 4.9 34 BULK-59aecdbe
21830 Bulk Product 4fc21aa8 Clothing $552.15 438 1.0 75 BULK-236bd80c
21831 Bulk Product 8a954c49 Books $844.61 338 4.1 86 BULK-03e7490e
21832 Bulk Product 34565005 Clothing $311.20 287 1.2 66 BULK-3e89dbaa
21833 Bulk Product 2cdd31e3 Clothing $264.95 325 3.3 44 BULK-4c2fbcb6
21834 Bulk Product b547a797 Home & Garden $811.79 203 3.6 34 BULK-9f3058af
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