Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

47 ms

Page Size

25

Current Page

698 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 698 Results Showing 17426 - 17450 of 24441

ID Name Category Price Stock Rating Reviews SKU
17985 Bulk Product 19c4b80a Clothing $327.51 11 3.7 60 BULK-624032ea
17986 Bulk Product 14d5aa40 Sports & Outdoors $947.39 424 1.5 5 BULK-4d963074
17987 Bulk Product 4b2426c6 Toys & Games $28.93 227 1.7 93 BULK-e346f84d
17988 Bulk Product e8b898f7 Toys & Games $866.11 496 2.8 34 BULK-823bf286
17989 Bulk Product 73c92928 Books $1,000.00 442 1.5 76 BULK-7f342684
17990 Bulk Product 33febebf Home & Garden $896.11 80 4.1 24 BULK-7a67eab2
17991 Bulk Product 82fc995d Clothing $539.14 136 5.0 1 BULK-8cca5cae
17992 Bulk Product c4dbcb1e Books $885.22 289 2.7 78 BULK-70dd6e5d
17993 Bulk Product 10323ca0 Sports & Outdoors $888.43 155 4.8 37 BULK-c17f2a5b
17994 Bulk Product c2a6d540 Toys & Games $266.49 378 3.5 55 BULK-9ff40a88
17995 Bulk Product 9ebb9b65 Clothing $299.52 245 0.3 83 BULK-6f8a749b
17996 Bulk Product a0e16d3b Clothing $170.52 300 2.8 90 BULK-070622f7
17997 Bulk Product 4c3d9154 Clothing $732.38 218 1.7 12 BULK-413d413a
17998 Bulk Product fab096ad Toys & Games $990.65 298 4.4 71 BULK-14f5e29b
17999 Bulk Product 95e775c7 Electronics $871.52 33 0.8 0 BULK-55e1348c
18000 Bulk Product 65761bfa Sports & Outdoors $42.22 123 2.8 93 BULK-b7718a70
18001 Bulk Product 21c3d252 Home & Garden $620.03 59 4.4 82 BULK-2b389167
18002 Bulk Product 96ea2c91 Toys & Games $597.82 234 0.5 53 BULK-86c758c0
18003 Bulk Product f64bf5ef Home & Garden $117.98 281 2.6 88 BULK-8b1448d2
18004 Bulk Product 03cfaa32 Clothing $478.66 392 2.6 33 BULK-f276c880
18005 Bulk Product 2298bbec Books $91.44 50 3.3 57 BULK-f5a5eb0b
18006 Bulk Product 96e23041 Books $531.87 321 2.4 90 BULK-51e30570
18007 Bulk Product c5d5d13f Electronics $196.07 254 2.6 91 BULK-a420f313
18008 Bulk Product 38a93820 Books $293.47 183 4.3 78 BULK-070773e3
18009 Bulk Product 4b5d1863 Books $994.09 100 3.9 80 BULK-958a8ec2
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