Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

47 ms

Page Size

25

Current Page

814 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 814 Results Showing 20326 - 20350 of 24441

ID Name Category Price Stock Rating Reviews SKU
20885 Bulk Product 8d8ee07b Toys & Games $440.26 284 2.0 34 BULK-fba6f2c3
20886 Bulk Product f2484ae0 Clothing $553.52 223 4.5 37 BULK-c7093a5e
20887 Bulk Product b7b914f0 Home & Garden $469.26 454 0.5 35 BULK-ad6a4a93
20888 Bulk Product c7c9d50e Home & Garden $350.10 427 0.1 31 BULK-9a06600f
20889 Bulk Product 7d392ff0 Clothing $454.32 29 4.9 0 BULK-bb6faa72
20890 Bulk Product 33776001 Electronics $756.37 126 4.9 20 BULK-356c37cd
20891 Bulk Product 08e2de4f Books $121.92 97 2.8 24 BULK-3172cd3f
20892 Bulk Product 68ea8bc1 Electronics $884.80 493 2.0 67 BULK-34a197be
20893 Bulk Product fed089b5 Sports & Outdoors $948.02 20 3.0 5 BULK-4ffc8029
20894 Bulk Product 9adda016 Home & Garden $988.96 173 3.8 15 BULK-e129b638
20895 Bulk Product f50a21e9 Books $54.50 321 4.6 68 BULK-9c2a4206
20896 Bulk Product 32e0f6bd Books $108.60 91 2.1 84 BULK-808022c0
20897 Bulk Product 4cd4e3ca Clothing $577.45 455 2.5 80 BULK-312f6cf5
20898 Bulk Product d5620d60 Electronics $851.20 475 5.0 80 BULK-8e1c459c
20899 Bulk Product ef33b27e Home & Garden $511.16 274 3.6 17 BULK-fc202c5b
20900 Bulk Product 47bdb920 Sports & Outdoors $701.26 415 4.7 19 BULK-4c19b3ba
20901 Bulk Product 20a071a3 Electronics $559.09 104 2.8 86 BULK-de51ceac
20902 Bulk Product dc04df9c Sports & Outdoors $124.08 231 3.3 69 BULK-b1b9f494
20903 Bulk Product 648e2925 Electronics $67.08 83 4.9 34 BULK-87def16e
20904 Bulk Product 710e0f55 Toys & Games $686.58 226 4.3 20 BULK-bbda1c59
20905 Bulk Product b61d2241 Clothing $474.74 72 0.9 52 BULK-9d2e989e
20906 Bulk Product 990b3bb3 Books $590.44 213 1.8 48 BULK-28314bf3
20907 Bulk Product 418d0c58 Sports & Outdoors $606.64 265 3.1 98 BULK-58f98d56
20908 Bulk Product ca74bf24 Electronics $295.91 103 2.4 92 BULK-0b2a7e9a
20909 Bulk Product bf71ae52 Toys & Games $265.30 127 1.2 70 BULK-386432f4
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