Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

53 ms

Page Size

25

Current Page

149 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 149 Results Showing 3701 - 3725 of 24441

ID Name Category Price Stock Rating Reviews SKU
4167 Mega Sports & Outdoors Product Classic Sports & Outdoors $142.00 57 1.8 753 SKU-004167
4168 Elite Books Product Lite Books $787.63 464 1.2 702 SKU-004168
4169 Elite Office Supplies Product Pro Office Supplies $905.27 78 2.5 458 SKU-004169
4170 Mega Clothing Product XL Clothing $14.01 100 1.6 876 SKU-004170
4171 Ultra Office Supplies Product XL Office Supplies $123.54 199 2.0 814 SKU-004171
4172 Pro Automotive Product Special Edition Automotive $212.85 292 3.3 55 SKU-004172
4173 Economy Clothing Product Max Clothing $736.17 45 3.5 695 SKU-004173
4174 Standard Home & Garden Product XL Home & Garden $190.65 126 2.6 468 SKU-004174
4175 Mega Automotive Product Lite Automotive $781.91 226 3.0 197 SKU-004175
4176 Pro Automotive Product Max Automotive $59.91 9 3.1 583 SKU-004176
4177 Economy Electronics Product Plus Electronics $470.84 113 3.5 561 SKU-004177
4178 Pro Toys & Games Product Plus Toys & Games $459.45 228 4.4 320 SKU-004178
4179 Ultra Clothing Product Mini Clothing $506.70 215 2.5 241 SKU-004179
4180 Economy Automotive Product Lite Automotive $256.10 294 1.6 534 SKU-004180
4181 Professional Clothing Product Classic Clothing $894.04 142 3.3 283 SKU-004181
4182 Elite Electronics Product Advanced Electronics $673.06 442 4.7 348 SKU-004182
4184 Professional Clothing Product Mini Clothing $50.39 470 2.7 295 SKU-004184
4185 Ultra Food & Grocery Product 2024 Food & Grocery $984.49 209 4.5 908 SKU-004185
4186 Mega Books Product Classic Books $754.30 265 3.3 966 SKU-004186
4187 Economy Food & Grocery Product Advanced Food & Grocery $448.35 475 1.4 827 SKU-004187
4188 Deluxe Health & Beauty Product Lite Health & Beauty $194.85 353 3.4 179 SKU-004188
4189 Super Home & Garden Product Pro Home & Garden $322.68 494 2.7 293 SKU-004189
4190 Deluxe Health & Beauty Product Special Edition Health & Beauty $163.31 373 4.1 858 SKU-004190
4191 Elite Clothing Product Classic Clothing $936.24 54 4.8 798 SKU-004191
4192 Pro Food & Grocery Product 2024 Food & Grocery $780.86 132 4.9 278 SKU-004192
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