Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

56 ms

Page Size

25

Current Page

7 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 7 Results Showing 151 - 175 of 24441

ID Name Category Price Stock Rating Reviews SKU
168 Premium Food & Grocery Product Mini Food & Grocery $223.95 312 4.8 232 SKU-000168
169 Professional Health & Beauty Product 2024 Health & Beauty $644.32 144 1.3 415 SKU-000169
170 Ultra Clothing Product Lite Clothing $190.55 317 1.6 905 SKU-000170
172 Professional Office Supplies Product Plus Office Supplies $739.26 287 4.0 375 SKU-000172
173 Pro Sports & Outdoors Product Pro Sports & Outdoors $349.49 283 3.8 733 SKU-000173
174 Standard Home & Garden Product Classic Home & Garden $817.00 189 3.9 62 SKU-000174
175 Mega Office Supplies Product Plus Office Supplies $169.22 318 3.0 332 SKU-000175
176 Pro Home & Garden Product Classic Home & Garden $820.64 0 4.0 919 SKU-000176
177 Mega Office Supplies Product 2024 Office Supplies $912.16 302 3.6 506 SKU-000177
178 Mega Food & Grocery Product Lite Food & Grocery $41.65 320 1.5 769 SKU-000178
179 Ultra Office Supplies Product Plus Office Supplies $100.55 393 1.3 425 SKU-000179
180 Elite Food & Grocery Product Max Food & Grocery $709.85 392 4.7 668 SKU-000180
181 Standard Sports & Outdoors Product Classic Sports & Outdoors $613.53 260 2.0 83 SKU-000181
182 Premium Health & Beauty Product Plus Health & Beauty $748.16 385 3.7 567 SKU-000182
183 Mega Electronics Product Plus Electronics $137.21 485 3.3 543 SKU-000183
184 Standard Toys & Games Product Max Toys & Games $675.00 82 2.4 658 SKU-000184
185 Super Health & Beauty Product Max Health & Beauty $814.40 410 4.4 579 SKU-000185
186 Professional Office Supplies Product Pro Office Supplies $326.82 25 2.6 841 SKU-000186
187 Ultra Home & Garden Product Lite Home & Garden $101.53 433 1.3 89 SKU-000187
188 Standard Clothing Product Mini Clothing $922.61 483 3.8 534 SKU-000188
189 Economy Electronics Product Advanced Electronics $637.35 112 3.9 514 SKU-000189
190 Ultra Toys & Games Product XL Toys & Games $542.04 462 2.3 359 SKU-000190
191 Premium Health & Beauty Product XL Health & Beauty $426.75 145 2.7 449 SKU-000191
192 Super Electronics Product Plus Electronics $729.25 222 3.1 681 SKU-000192
193 Professional Clothing Product Max Clothing $219.61 297 1.5 351 SKU-000193
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