Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

265 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 265 Results Showing 6601 - 6625 of 24441

ID Name Category Price Stock Rating Reviews SKU
7160 Bulk Product 5e3c6951 Toys & Games $923.11 112 2.5 80 BULK-f335f259
7161 Bulk Product 36120d80 Sports & Outdoors $385.23 179 0.7 14 BULK-554a8328
7162 Bulk Product de0e30ba Clothing $802.86 173 0.5 53 BULK-5d78f363
7163 Bulk Product ce913e72 Toys & Games $645.93 494 3.2 18 BULK-f714d5c2
7164 Bulk Product 480db72b Home & Garden $509.92 447 0.0 22 BULK-cf664baa
7165 Bulk Product 509e1df3 Clothing $817.62 144 0.9 47 BULK-644895f9
7166 Bulk Product 5d7aabec Home & Garden $118.33 10 4.1 20 BULK-443c13f9
7167 Bulk Product 977efc13 Toys & Games $496.13 344 2.0 10 BULK-16e18285
7168 Bulk Product a452b7ff Clothing $556.94 496 4.6 16 BULK-0b1e1c93
7169 Bulk Product c9b92ca8 Electronics $220.19 262 0.8 1 BULK-30edd431
7170 Bulk Product 31f01fdd Clothing $628.50 405 0.3 52 BULK-bdfb4699
7171 Bulk Product 1b2d8ae5 Books $688.55 332 2.8 0 BULK-aecf2648
7172 Bulk Product 856a998a Clothing $975.07 252 0.5 75 BULK-0484a196
7173 Bulk Product 3b99a6cc Sports & Outdoors $109.05 442 1.2 33 BULK-48d9d2e6
7174 Bulk Product be0f195c Home & Garden $59.80 380 0.5 38 BULK-dcaa22bf
7175 Bulk Product e5cd9817 Clothing $365.07 170 4.9 45 BULK-9c3096eb
7176 Bulk Product db4352d2 Toys & Games $537.86 62 4.2 99 BULK-4a74433b
7177 Bulk Product 659e481f Home & Garden $54.61 317 4.4 55 BULK-412e83bd
7178 Bulk Product 4d0e85b8 Sports & Outdoors $691.98 498 1.0 90 BULK-c12a30bd
7179 Bulk Product 3180ecfb Books $540.54 454 1.1 27 BULK-d84616a3
7180 Bulk Product d85d8535 Toys & Games $992.00 403 0.5 20 BULK-cf99fafa
7181 Bulk Product 8667b043 Clothing $81.15 283 2.0 73 BULK-8cd39500
7182 Bulk Product 38c88010 Toys & Games $363.86 272 4.9 71 BULK-c4aae766
7183 Bulk Product 26ce2930 Clothing $137.90 145 4.4 31 BULK-1abc9415
7184 Bulk Product 74e0a0c7 Books $31.67 110 4.9 42 BULK-27799d16
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