Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

51 ms

Page Size

25

Current Page

413 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 413 Results Showing 10301 - 10325 of 24441

ID Name Category Price Stock Rating Reviews SKU
10860 Bulk Product 65993236 Home & Garden $577.68 76 0.7 50 BULK-5c251abe
10861 Bulk Product c966849d Books $835.22 116 4.5 36 BULK-ff65bb11
10862 Bulk Product a04e29f5 Books $151.42 430 2.8 53 BULK-8cc141d2
10863 Bulk Product eb680c8b Electronics $700.34 196 3.6 31 BULK-656081ef
10864 Bulk Product dd8dbd0b Books $50.40 97 3.3 29 BULK-34ca2c8e
10865 Bulk Product 60563cfc Clothing $559.08 276 4.2 3 BULK-383e5823
10866 Bulk Product b066bb2c Books $249.96 138 4.9 70 BULK-d1cf4891
10867 Bulk Product d81fbad7 Books $787.70 240 1.7 84 BULK-407f3d34
10868 Bulk Product aa168e82 Clothing $885.04 324 3.4 5 BULK-a3d18296
10869 Bulk Product 4dc38997 Toys & Games $51.17 218 1.4 53 BULK-f739a3a4
10870 Bulk Product 4539ad0c Clothing $109.24 396 4.4 10 BULK-e6a80e2d
10871 Bulk Product 518c03e3 Electronics $671.77 89 4.1 55 BULK-88af57f7
10872 Bulk Product b72985c7 Electronics $405.32 155 4.7 71 BULK-85e544fb
10873 Bulk Product 04cfe8a0 Clothing $19.56 104 0.9 15 BULK-9540f363
10874 Bulk Product fa2c3902 Books $633.24 264 4.4 75 BULK-8bd7526d
10875 Bulk Product 92030288 Clothing $784.54 464 2.4 72 BULK-8ff055e1
10876 Bulk Product ba61691f Clothing $42.83 334 3.4 63 BULK-1e7356ad
10877 Bulk Product 86cbb55e Home & Garden $151.53 375 3.0 50 BULK-bee9953f
10878 Bulk Product b207294d Home & Garden $899.16 266 2.3 96 BULK-046bbf6f
10879 Bulk Product be8bc27d Toys & Games $219.96 246 4.2 67 BULK-304a53c6
10880 Bulk Product 0d26f7b4 Electronics $737.39 65 4.3 21 BULK-ab4d5814
10881 Bulk Product e4f7ec79 Electronics $622.10 65 2.6 96 BULK-fb0a17bd
10882 Bulk Product 61028479 Sports & Outdoors $90.67 336 0.2 76 BULK-64eb3a12
10883 Bulk Product df0b73ba Electronics $152.36 413 0.5 59 BULK-0bc6a7fb
10884 Bulk Product a48bdd05 Books $161.72 427 4.9 54 BULK-de3c6ba0
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