Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

27 ms

Page Size

25

Current Page

895 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 895 Results Showing 22351 - 22375 of 24441

ID Name Category Price Stock Rating Reviews SKU
22910 Bulk Product c4bbee81 Clothing $505.40 423 3.7 38 BULK-5e83fb1f
22911 Bulk Product fc5f62ec Home & Garden $593.56 408 2.0 64 BULK-f100afd8
22912 Bulk Product b8dbb596 Home & Garden $575.00 240 1.3 18 BULK-9ba0064d
22913 Bulk Product 5d537553 Toys & Games $269.37 470 0.2 35 BULK-a2d28379
22914 Bulk Product d8025f2f Sports & Outdoors $974.21 220 0.3 57 BULK-0c41d7af
22915 Bulk Product b5b38a4e Electronics $528.84 186 0.7 3 BULK-a4cd3849
22916 Bulk Product cfc8c62e Electronics $1,006.46 395 4.4 51 BULK-7e5abff9
22917 Bulk Product e8ad70e0 Sports & Outdoors $465.06 251 3.7 49 BULK-87353733
22918 Bulk Product 7c7079f0 Home & Garden $834.91 422 3.4 73 BULK-75633678
22919 Bulk Product b14256a5 Electronics $481.86 225 4.4 24 BULK-c5ef576f
22920 Bulk Product 79c23208 Clothing $127.46 339 0.6 91 BULK-0235b8c2
22921 Bulk Product 1da08d50 Books $703.30 25 2.8 26 BULK-7754d0c2
22922 Bulk Product 0336662e Home & Garden $189.07 64 0.7 0 BULK-689f90b4
22923 Bulk Product 68cbd3d6 Toys & Games $10.76 33 2.4 44 BULK-386e2e4b
22924 Bulk Product 235717d3 Home & Garden $255.44 226 3.1 8 BULK-f130db6a
22925 Bulk Product d47f93bb Electronics $414.69 227 3.7 56 BULK-cf959298
22926 Bulk Product 0b6d7c35 Books $933.70 36 0.2 56 BULK-c23ad07d
22927 Bulk Product 8be111aa Toys & Games $726.68 285 2.6 99 BULK-70f1b4a5
22928 Bulk Product 20bf5ee5 Home & Garden $830.43 229 1.3 9 BULK-06a50480
22929 Bulk Product 5feb5213 Toys & Games $453.90 72 3.2 90 BULK-275aeb2f
22930 Bulk Product a52a17f3 Sports & Outdoors $524.34 271 2.3 36 BULK-08fe2f16
22931 Bulk Product bc1c8620 Home & Garden $535.19 33 3.0 2 BULK-09fba6ce
22932 Bulk Product c55b4e12 Home & Garden $655.98 12 4.2 66 BULK-1b80477e
22933 Bulk Product 2c17bd73 Toys & Games $741.66 442 1.8 75 BULK-e73cf40e
22934 Bulk Product 6a097a04 Books $280.61 53 3.2 64 BULK-e914ec47
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