Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

25

Current Page

176 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 176 Results Showing 4376 - 4400 of 24441

ID Name Category Price Stock Rating Reviews SKU
4930 Elite Food & Grocery Product 2024 Food & Grocery $217.76 414 1.5 677 SKU-004930
4931 Pro Books Product Lite Books $97.50 238 1.8 312 SKU-004931
4932 Elite Food & Grocery Product Pro Food & Grocery $107.14 462 2.0 916 SKU-004932
4933 Mega Books Product Classic Books $231.24 251 4.7 715 SKU-004933
4935 Premium Clothing Product Advanced Clothing $202.58 93 2.0 3 SKU-004935
4936 Economy Food & Grocery Product XL Food & Grocery $965.37 326 1.4 919 SKU-004936
4937 Economy Sports & Outdoors Product Plus Sports & Outdoors $273.92 110 1.2 655 SKU-004937
4938 Deluxe Sports & Outdoors Product Lite Sports & Outdoors $351.75 18 2.6 678 SKU-004938
4939 Super Health & Beauty Product Plus Health & Beauty $840.62 442 1.7 674 SKU-004939
4940 Super Electronics Product Mini Electronics $49.56 489 3.7 649 SKU-004940
4941 Elite Clothing Product 2024 Clothing $517.32 375 1.3 249 SKU-004941
4942 Professional Office Supplies Product 2024 Office Supplies $185.98 75 4.2 351 SKU-004942
4943 Ultra Food & Grocery Product Pro Food & Grocery $242.32 225 1.8 486 SKU-004943
4944 Standard Automotive Product Advanced Automotive $154.03 443 2.6 992 SKU-004944
4945 Ultra Sports & Outdoors Product Lite Sports & Outdoors $33.69 437 2.5 157 SKU-004945
4946 Economy Sports & Outdoors Product Advanced Sports & Outdoors $774.50 400 4.8 614 SKU-004946
4947 Standard Automotive Product Advanced Automotive $669.31 269 3.4 483 SKU-004947
4948 Economy Automotive Product Plus Automotive $884.30 330 1.2 718 SKU-004948
4949 Super Clothing Product Classic Clothing $553.61 74 3.5 259 SKU-004949
4950 Mega Home & Garden Product 2024 Home & Garden $416.11 96 2.2 387 SKU-004950
4951 Standard Health & Beauty Product Lite Health & Beauty $165.16 21 1.6 872 SKU-004951
4952 Pro Books Product Lite Books $296.06 114 1.4 350 SKU-004952
4954 Professional Food & Grocery Product 2024 Food & Grocery $457.66 414 2.9 45 SKU-004954
4955 Premium Food & Grocery Product Plus Food & Grocery $964.73 491 2.4 243 SKU-004955
4956 Deluxe Toys & Games Product Classic Toys & Games $596.60 218 3.8 243 SKU-004956
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