Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

34 ms

Page Size

25

Current Page

828 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 828 Results Showing 20676 - 20700 of 24441

ID Name Category Price Stock Rating Reviews SKU
21235 Bulk Product b6fe14d3 Electronics $777.93 56 1.4 32 BULK-1c32c7e1
21236 Bulk Product cdb38a01 Toys & Games $380.83 263 3.2 3 BULK-761aef19
21237 Bulk Product 92380105 Home & Garden $345.58 434 0.9 78 BULK-ffd23d17
21238 Bulk Product 2f07bf13 Clothing $228.20 38 1.5 28 BULK-b65c0244
21239 Bulk Product ead2ef33 Home & Garden $526.88 285 3.3 57 BULK-18c0ccc4
21240 Bulk Product 85f00da2 Electronics $691.43 74 0.7 61 BULK-e2e71b0c
21241 Bulk Product f9a4154c Books $984.56 142 4.0 28 BULK-15b745c5
21242 Bulk Product d7886eec Electronics $164.73 79 2.5 87 BULK-4a27fa79
21243 Bulk Product 6870df96 Books $41.22 330 2.7 70 BULK-44f26174
21244 Bulk Product 91435bc0 Clothing $961.05 265 2.4 89 BULK-5e12b935
21245 Bulk Product 9057a481 Home & Garden $429.57 43 0.3 21 BULK-0912f4ca
21246 Bulk Product 358b74cc Toys & Games $732.03 272 2.6 12 BULK-568a3363
21247 Bulk Product 27cc893c Clothing $312.31 297 3.8 62 BULK-43ffdd42
21248 Bulk Product 203a5e61 Home & Garden $368.33 167 4.2 52 BULK-9cec6730
21249 Bulk Product c38c994a Electronics $529.91 218 3.4 27 BULK-0146f751
21250 Bulk Product 722a1931 Home & Garden $17.26 347 1.5 30 BULK-37c17de9
21251 Bulk Product a8674d30 Books $786.81 98 2.1 76 BULK-f5b90ece
21252 Bulk Product 03ae5a8a Home & Garden $420.23 263 4.6 66 BULK-bfcb87c9
21253 Bulk Product 8465964a Clothing $426.90 212 3.2 49 BULK-45a7f6cf
21254 Bulk Product d560e46f Home & Garden $176.98 258 3.1 66 BULK-e4e27564
21255 Bulk Product ca607a8b Electronics $711.93 47 4.4 51 BULK-fa69772e
21256 Bulk Product 0412ec5e Electronics $417.96 425 0.8 68 BULK-c53109da
21257 Bulk Product 722273d8 Clothing $310.07 301 3.3 31 BULK-04c2da77
21258 Bulk Product ab70221d Electronics $315.18 213 2.0 31 BULK-b5e12ed6
21259 Bulk Product aa5d8196 Toys & Games $545.26 368 1.0 96 BULK-3d50fddb
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