Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

25

Current Page

636 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 636 Results Showing 15876 - 15900 of 24441

ID Name Category Price Stock Rating Reviews SKU
16435 Bulk Product 8572a8a2 Electronics $562.10 388 3.5 55 BULK-abb17b6d
16436 Bulk Product 1d7be1b6 Home & Garden $644.30 259 1.7 81 BULK-470f9e7a
16437 Bulk Product 52aff8c7 Electronics $894.72 10 3.2 82 BULK-1731c13b
16438 Bulk Product c4a80d85 Books $208.65 275 2.3 38 BULK-04615753
16439 Bulk Product 608f70ce Home & Garden $446.62 100 4.6 86 BULK-fc81da38
16440 Bulk Product 6e8d888d Home & Garden $365.55 85 3.0 88 BULK-a8e7a446
16441 Bulk Product f2ed94cf Clothing $676.79 279 3.8 75 BULK-6d92b9ed
16442 Bulk Product 5df6780f Books $432.84 187 2.0 75 BULK-60901d93
16443 Bulk Product 4f66327e Electronics $569.04 145 0.3 73 BULK-14155ab7
16444 Bulk Product 3938f871 Books $746.34 286 0.8 32 BULK-11d2f46f
16445 Bulk Product 4b91b42a Books $463.18 499 0.7 22 BULK-bad39b51
16446 Bulk Product 8adbb97f Home & Garden $256.59 159 2.8 57 BULK-b0460ae9
16447 Bulk Product 277f2cb5 Books $724.37 54 1.7 92 BULK-7bbd8e0e
16448 Bulk Product 5c668228 Sports & Outdoors $85.82 35 5.0 99 BULK-6d4a39e7
16449 Bulk Product f0bdc3bb Sports & Outdoors $107.79 430 4.7 99 BULK-ff005c78
16450 Bulk Product c752ed5e Books $264.14 306 1.4 34 BULK-e8eb3666
16451 Bulk Product c9f3843d Electronics $282.24 95 4.5 16 BULK-12a5e2e7
16452 Bulk Product c0a550b1 Toys & Games $327.61 183 1.5 7 BULK-ddfe1153
16453 Bulk Product 3b4efeec Books $548.36 334 1.2 32 BULK-6024db0a
16454 Bulk Product a9abbc02 Clothing $909.03 199 0.9 88 BULK-dd46498c
16455 Bulk Product 301e829c Electronics $733.53 392 4.3 0 BULK-d9b6f89c
16456 Bulk Product d910ddb6 Clothing $869.23 410 1.0 90 BULK-cc14eddc
16457 Bulk Product 908a6d66 Electronics $658.78 288 0.1 63 BULK-bef668ed
16458 Bulk Product cbf17082 Toys & Games $732.14 61 0.5 55 BULK-b47ee504
16459 Bulk Product f7613ed7 Books $612.45 286 2.6 30 BULK-42b3474d
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