Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

26 ms

Page Size

25

Current Page

901 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 901 Results Showing 22501 - 22525 of 24441

ID Name Category Price Stock Rating Reviews SKU
23060 Bulk Product 2a12ec37 Clothing $1,002.57 380 1.2 48 BULK-696f1e7d
23061 Bulk Product 628629b2 Electronics $988.31 64 2.9 28 BULK-d39e8694
23062 Bulk Product 7961bd89 Electronics $901.69 235 1.7 68 BULK-675105e0
23063 Bulk Product c9cf21ba Electronics $320.11 213 1.1 14 BULK-25bc65cc
23064 Bulk Product abc4bd62 Sports & Outdoors $465.23 259 3.9 38 BULK-95107bb6
23065 Bulk Product 3087681e Clothing $890.31 256 2.1 71 BULK-37cc968b
23066 Bulk Product 2acc2468 Books $529.80 53 0.5 67 BULK-1e1aef15
23067 Bulk Product c9da8658 Books $358.56 395 0.7 4 BULK-94981845
23068 Bulk Product d57e529f Electronics $666.36 463 0.8 84 BULK-873139a7
23069 Bulk Product a0dc781f Books $496.77 122 4.7 48 BULK-1b70a997
23070 Bulk Product 99f3312e Toys & Games $291.64 282 3.4 50 BULK-bc68c363
23071 Bulk Product 4fe23423 Toys & Games $808.90 35 4.4 18 BULK-8d5d7aee
23072 Bulk Product c04e3814 Electronics $793.63 387 2.6 43 BULK-d48964d2
23073 Bulk Product c07b168a Books $434.72 380 4.6 47 BULK-7f52ee3e
23074 Bulk Product 6cc10db8 Home & Garden $75.96 494 1.7 8 BULK-e7010c0e
23075 Bulk Product 467a8019 Clothing $974.24 48 1.0 26 BULK-c6721427
23076 Bulk Product c95c50e2 Electronics $65.32 401 1.1 53 BULK-0ed9249a
23077 Bulk Product 9cfca50d Electronics $592.11 422 1.8 19 BULK-34a9f61f
23078 Bulk Product cdcc4dd3 Books $183.81 172 2.1 38 BULK-9bb42de8
23079 Bulk Product 2068534e Sports & Outdoors $976.85 436 3.6 67 BULK-891e897f
23080 Bulk Product 64aa84f7 Home & Garden $181.72 162 1.7 88 BULK-830b5a76
23081 Bulk Product cfffcb54 Electronics $20.82 124 0.0 46 BULK-8a9fad57
23082 Bulk Product cc2d542f Electronics $173.96 231 0.3 47 BULK-e727cda1
23083 Bulk Product 4c2708ae Toys & Games $640.17 349 3.3 75 BULK-0bf07300
23084 Bulk Product 5753c805 Books $432.43 408 5.0 1 BULK-2bea90ef
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