Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

27 ms

Page Size

25

Current Page

931 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 931 Results Showing 23251 - 23275 of 24441

ID Name Category Price Stock Rating Reviews SKU
23810 Bulk Product 54b31a98 Home & Garden $706.43 230 4.8 92 BULK-23e3c246
23811 Bulk Product 653ae369 Clothing $215.36 380 4.6 25 BULK-53604f5d
23812 Bulk Product 850b000e Sports & Outdoors $808.24 348 4.9 74 BULK-08c7ae64
23813 Bulk Product 465a0f85 Electronics $905.58 459 1.3 89 BULK-b00a06ea
23814 Bulk Product 963dba33 Sports & Outdoors $833.70 217 3.3 41 BULK-1f11e223
23815 Bulk Product 00f72aae Clothing $139.93 299 1.1 66 BULK-2c4cde03
23816 Bulk Product 29a32212 Toys & Games $544.18 228 0.2 9 BULK-88e06f62
23817 Bulk Product add6e14d Electronics $987.20 107 4.5 21 BULK-f17f9ab5
23818 Bulk Product 7f22410f Clothing $535.68 293 4.4 91 BULK-05439037
23819 Bulk Product 670551ee Electronics $380.53 10 4.4 61 BULK-40ca203e
23820 Bulk Product ebedf863 Clothing $332.76 283 1.5 91 BULK-f43dea59
23821 Bulk Product 0df8edff Clothing $928.97 39 3.4 1 BULK-a845d48b
23822 Bulk Product df2353f8 Books $86.69 156 3.8 73 BULK-54f3aa40
23823 Bulk Product 3207f77e Toys & Games $623.12 415 4.6 42 BULK-e0e57676
23824 Bulk Product 2e1fbb5e Books $745.81 120 0.6 50 BULK-253ca182
23825 Bulk Product 4f6e8c3b Home & Garden $164.69 366 3.7 85 BULK-7cf141be
23826 Bulk Product e94c1971 Home & Garden $942.71 464 3.4 39 BULK-c335c660
23827 Bulk Product 10bbf6f2 Books $858.84 492 2.1 8 BULK-faf4447d
23828 Bulk Product eb413854 Clothing $752.21 244 1.6 10 BULK-18d45726
23829 Bulk Product 7b61b8d3 Clothing $184.39 480 2.4 37 BULK-bc2c2f7d
23830 Bulk Product ca16d32c Electronics $234.51 399 2.0 61 BULK-860031eb
23831 Bulk Product 204c3e3c Books $121.49 227 4.9 78 BULK-07c5b053
23832 Bulk Product 166c043c Electronics $838.03 245 3.4 74 BULK-5bd93cfc
23833 Bulk Product 2b81c11f Home & Garden $849.48 91 4.6 88 BULK-22dc2cb2
23834 Bulk Product d8ba5386 Home & Garden $484.03 481 4.6 45 BULK-679b9e06
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