Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

575 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 575 Results Showing 14351 - 14375 of 24441

ID Name Category Price Stock Rating Reviews SKU
14910 Bulk Product a367a781 Home & Garden $793.51 231 3.3 48 BULK-9fda8580
14911 Bulk Product ad0b7e89 Home & Garden $872.93 220 3.3 81 BULK-6806ed1b
14912 Bulk Product 14e20645 Home & Garden $363.99 477 4.0 50 BULK-d5115803
14913 Bulk Product 75e41a41 Home & Garden $999.70 321 0.7 74 BULK-c7f008b1
14914 Bulk Product 9fb309aa Sports & Outdoors $122.16 257 3.3 81 BULK-b96aa604
14915 Bulk Product d67d03ea Electronics $543.22 172 3.8 45 BULK-11f23c73
14916 Bulk Product 15cc9794 Toys & Games $164.01 118 2.5 10 BULK-3dd74ae9
14917 Bulk Product 44111e45 Electronics $845.84 432 3.7 75 BULK-59183a1d
14918 Bulk Product 9c48f1d9 Home & Garden $774.02 452 0.1 80 BULK-68202c57
14919 Bulk Product 4f63cbf2 Sports & Outdoors $152.33 322 3.3 75 BULK-3f3704b4
14920 Bulk Product 360d0e7e Toys & Games $477.98 138 4.4 30 BULK-56a7aafd
14921 Bulk Product 9bcdec0c Sports & Outdoors $589.98 495 0.9 53 BULK-8a5f6593
14922 Bulk Product 163b7a5c Books $942.26 478 3.5 20 BULK-ab1d05d0
14923 Bulk Product 25fb30e8 Books $208.51 94 2.2 46 BULK-291d0414
14924 Bulk Product 810b7188 Sports & Outdoors $655.73 195 1.9 65 BULK-a026dca8
14925 Bulk Product b898450d Clothing $500.71 79 2.6 37 BULK-358ec469
14926 Bulk Product 5647f7a5 Home & Garden $682.29 409 5.0 96 BULK-51edf24a
14927 Bulk Product 9e25a7c9 Sports & Outdoors $696.78 477 3.7 36 BULK-000917e5
14928 Bulk Product f7abb6e6 Sports & Outdoors $812.79 115 2.5 63 BULK-7cc6bfbd
14929 Bulk Product d9fab138 Home & Garden $204.12 307 2.5 10 BULK-217e3cf1
14930 Bulk Product 6e00c367 Clothing $135.59 254 4.7 88 BULK-4e2e049f
14931 Bulk Product 81deb3d7 Home & Garden $129.78 459 4.8 69 BULK-c2698bd4
14932 Bulk Product 8fbda548 Sports & Outdoors $137.94 459 0.8 96 BULK-4b830d9b
14933 Bulk Product 86432987 Books $340.31 62 2.3 35 BULK-d9c90c5c
14934 Bulk Product 989f8f08 Electronics $243.09 67 2.8 46 BULK-df964c58
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