Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

40 ms

Page Size

25

Current Page

453 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 453 Results Showing 11301 - 11325 of 24441

ID Name Category Price Stock Rating Reviews SKU
11860 Bulk Product b5ce5693 Home & Garden $133.42 133 1.0 49 BULK-bb375199
11861 Bulk Product 9960c450 Home & Garden $258.21 369 2.5 3 BULK-9922b8dc
11862 Bulk Product 07952fa3 Toys & Games $211.02 186 0.4 7 BULK-173c8c11
11863 Bulk Product e75328f7 Home & Garden $827.60 139 2.0 11 BULK-6d20737a
11864 Bulk Product 8cced505 Electronics $151.20 498 3.3 44 BULK-550031d1
11865 Bulk Product 5a257602 Toys & Games $591.11 314 3.0 48 BULK-5fea7c3d
11866 Bulk Product 77dc8aaa Clothing $213.67 54 4.7 7 BULK-4633eb26
11867 Bulk Product 70d3bf67 Books $357.91 215 3.9 86 BULK-f40f2e75
11868 Bulk Product c01c2a6e Books $557.61 171 3.3 60 BULK-40f5e7ab
11869 Bulk Product 70aa0f86 Electronics $130.77 403 1.4 91 BULK-73b2b507
11870 Bulk Product 90811b59 Toys & Games $727.81 479 4.3 81 BULK-824c161b
11871 Bulk Product 314bfe3c Electronics $564.22 492 4.9 69 BULK-73d9d320
11872 Bulk Product aa41ecde Clothing $588.81 94 2.2 75 BULK-6324b3d6
11873 Bulk Product 562812c6 Books $109.80 483 2.6 9 BULK-af47a21f
11874 Bulk Product 865d672a Toys & Games $562.20 491 2.7 23 BULK-3b60a09a
11875 Bulk Product 247767a0 Electronics $296.10 326 1.3 96 BULK-16491be6
11876 Bulk Product 418e8227 Home & Garden $894.42 425 4.5 65 BULK-8fab7be3
11877 Bulk Product b7f428bd Toys & Games $917.30 427 2.3 37 BULK-64cdc486
11878 Bulk Product 57b2de4b Home & Garden $991.06 289 0.7 19 BULK-16f13391
11879 Bulk Product 79c1b6e1 Clothing $865.82 170 3.8 3 BULK-6131a2e7
11880 Bulk Product 349c4f15 Sports & Outdoors $918.87 284 4.7 17 BULK-c7fe2819
11881 Bulk Product 831482d7 Books $69.87 316 3.9 84 BULK-74c76cf3
11882 Bulk Product 04f1442d Sports & Outdoors $918.19 58 1.1 4 BULK-36dc3c04
11883 Bulk Product 279483f6 Home & Garden $780.27 433 4.0 10 BULK-db4041f3
11884 Bulk Product eb31cc7b Clothing $901.69 261 1.6 14 BULK-174d4817
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