Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

51 ms

Page Size

25

Current Page

80 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 80 Results Showing 1976 - 2000 of 24441

ID Name Category Price Stock Rating Reviews SKU
2225 Super Food & Grocery Product Special Edition Food & Grocery $533.74 153 2.1 432 SKU-002225
2226 Professional Health & Beauty Product Max Health & Beauty $439.81 141 3.0 319 SKU-002226
2227 Standard Automotive Product XL Automotive $704.21 90 4.2 484 SKU-002227
2228 Mega Books Product Pro Books $854.18 61 1.3 401 SKU-002228
2229 Deluxe Books Product XL Books $343.22 229 2.0 447 SKU-002229
2230 Economy Electronics Product Advanced Electronics $58.46 371 4.8 504 SKU-002230
2231 Economy Home & Garden Product Mini Home & Garden $262.96 345 2.1 343 SKU-002231
2232 Premium Books Product Classic Books $671.77 313 5.0 377 SKU-002232
2233 Super Health & Beauty Product Plus Health & Beauty $815.74 9 1.5 327 SKU-002233
2234 Pro Food & Grocery Product Plus Food & Grocery $541.44 324 2.4 4 SKU-002234
2235 Ultra Health & Beauty Product Lite Health & Beauty $475.16 464 2.4 412 SKU-002235
2236 Professional Health & Beauty Product Plus Health & Beauty $469.00 442 2.7 944 SKU-002236
2237 Ultra Sports & Outdoors Product Advanced Sports & Outdoors $555.86 347 3.4 930 SKU-002237
2238 Deluxe Health & Beauty Product Plus Health & Beauty $293.80 249 1.3 15 SKU-002238
2239 Standard Home & Garden Product XL Home & Garden $572.57 189 1.5 638 SKU-002239
2240 Deluxe Electronics Product Advanced Electronics $267.39 178 2.3 431 SKU-002240
2241 Mega Toys & Games Product Plus Toys & Games $98.77 397 1.6 884 SKU-002241
2242 Ultra Clothing Product Advanced Clothing $290.54 459 2.0 307 SKU-002242
2243 Elite Sports & Outdoors Product Mini Sports & Outdoors $619.73 175 2.2 946 SKU-002243
2244 Economy Food & Grocery Product Special Edition Food & Grocery $431.40 27 4.4 919 SKU-002244
2245 Economy Clothing Product Advanced Clothing $108.17 89 3.9 974 SKU-002245
2246 Professional Electronics Product Special Edition Electronics $362.49 181 1.1 244 SKU-002246
2247 Pro Electronics Product XL Electronics $334.52 479 4.1 183 SKU-002247
2248 Economy Electronics Product Advanced Electronics $815.01 55 1.5 634 SKU-002248
2249 Pro Sports & Outdoors Product Mini Sports & Outdoors $883.49 280 2.8 559 SKU-002249
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