Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

51 ms

Page Size

25

Current Page

701 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 701 Results Showing 17501 - 17525 of 24441

ID Name Category Price Stock Rating Reviews SKU
18060 Bulk Product 0b22c683 Home & Garden $858.35 209 1.1 94 BULK-2d6ba252
18061 Bulk Product a3a9f2fb Toys & Games $787.08 56 0.6 4 BULK-65c11675
18062 Bulk Product 51ed06a1 Sports & Outdoors $535.07 394 5.0 60 BULK-292db9cd
18063 Bulk Product 35ec9c02 Home & Garden $275.78 374 2.9 79 BULK-7d255395
18064 Bulk Product 2b6ab943 Home & Garden $780.32 365 3.8 60 BULK-323fb477
18065 Bulk Product 7061de18 Toys & Games $837.79 297 3.2 10 BULK-deceef2a
18066 Bulk Product 4fbb0389 Clothing $644.74 234 0.9 80 BULK-5a65f45d
18067 Bulk Product 8c8afe16 Clothing $443.10 164 1.4 35 BULK-415010b9
18068 Bulk Product 01b115a7 Clothing $227.06 216 2.8 36 BULK-9b951700
18069 Bulk Product e3b6180a Toys & Games $1,002.20 390 2.7 89 BULK-e5f620ee
18070 Bulk Product 7f1e78c8 Clothing $694.91 91 0.1 41 BULK-a5554d54
18071 Bulk Product de797274 Electronics $438.33 260 4.2 48 BULK-776e7300
18072 Bulk Product a197765f Sports & Outdoors $387.01 480 0.5 62 BULK-c93fcacf
18073 Bulk Product efbfd792 Books $197.94 478 3.6 79 BULK-aefe5adf
18074 Bulk Product 0c4c5e35 Home & Garden $672.47 262 1.1 6 BULK-ee0c798e
18075 Bulk Product 1099b8ff Sports & Outdoors $170.88 464 0.9 1 BULK-d0c772db
18076 Bulk Product de6461e7 Sports & Outdoors $632.30 360 0.4 59 BULK-489416d2
18077 Bulk Product 6e552b34 Toys & Games $74.21 212 2.1 26 BULK-3f30be67
18078 Bulk Product 21cb343a Sports & Outdoors $573.73 47 1.2 19 BULK-a9616e89
18079 Bulk Product 8b7f08ad Clothing $469.27 170 1.7 74 BULK-2bd4b154
18080 Bulk Product bed078cf Clothing $331.14 218 2.3 39 BULK-60fd2c7c
18081 Bulk Product b3085c96 Toys & Games $861.20 265 0.6 97 BULK-b8ef4f08
18082 Bulk Product 70f1a4b6 Home & Garden $360.00 418 4.6 48 BULK-503f88e5
18083 Bulk Product 2a670257 Sports & Outdoors $736.10 170 4.6 20 BULK-5168291d
18084 Bulk Product 9f06983b Sports & Outdoors $683.23 350 0.8 35 BULK-5fb01269
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