Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

27 ms

Page Size

25

Current Page

418 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 418 Results Showing 10426 - 10450 of 24441

ID Name Category Price Stock Rating Reviews SKU
10985 Bulk Product e4f5d82f Home & Garden $445.61 243 2.6 26 BULK-817b200f
10986 Bulk Product 83adf26e Books $663.46 398 0.5 61 BULK-3ae7faca
10987 Bulk Product c697171c Sports & Outdoors $238.09 142 3.7 95 BULK-c6550f4f
10988 Bulk Product aa399102 Books $910.00 235 2.6 27 BULK-fdbcbad3
10989 Bulk Product 1953b2af Electronics $936.31 345 1.7 91 BULK-280237d9
10990 Bulk Product 9a04c933 Books $461.66 288 1.2 39 BULK-f2f908e2
10991 Bulk Product bdd447f3 Books $585.60 402 1.3 97 BULK-005f1825
10992 Bulk Product 253b2aa6 Home & Garden $670.65 428 3.3 5 BULK-91b1461b
10993 Bulk Product dacf73f0 Sports & Outdoors $465.21 294 3.4 3 BULK-e73d74e7
10994 Bulk Product 00980193 Sports & Outdoors $541.53 218 3.0 93 BULK-ba43623a
10995 Bulk Product 83c56f59 Home & Garden $224.10 92 4.5 7 BULK-a4ac8a9a
10996 Bulk Product 750bec5f Home & Garden $552.57 61 1.7 1 BULK-401faf54
10997 Bulk Product e4a0c5ee Clothing $304.95 274 3.7 92 BULK-9d804657
10998 Bulk Product 98b3bc3a Home & Garden $72.79 498 3.7 43 BULK-6661881c
10999 Bulk Product 2ffae035 Sports & Outdoors $737.45 96 1.3 64 BULK-f802d8d3
11000 Bulk Product ec011df1 Home & Garden $474.20 475 3.3 44 BULK-eeda1084
11001 Bulk Product ba34fff0 Home & Garden $351.94 428 4.8 72 BULK-9558bb2d
11002 Bulk Product c1997fa0 Toys & Games $178.51 195 5.0 76 BULK-ceb68bf7
11003 Bulk Product 8465c4a6 Home & Garden $237.20 211 4.5 42 BULK-9a24cd06
11004 Bulk Product 5ffb91f1 Clothing $529.11 455 4.1 19 BULK-e66b2bd5
11005 Bulk Product 1d19d410 Books $727.66 302 3.2 10 BULK-f3c7b92a
11006 Bulk Product 3d000dd0 Toys & Games $388.86 409 5.0 22 BULK-914d3358
11007 Bulk Product 8cbe84d9 Sports & Outdoors $145.65 230 1.5 4 BULK-65ff34e8
11008 Bulk Product 3d9cc6af Home & Garden $530.97 78 1.4 11 BULK-d4ede0aa
11009 Bulk Product 99c793ca Clothing $745.23 368 0.5 76 BULK-bf3e6a37
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