Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

22 ms

Page Size

25

Current Page

511 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 511 Results Showing 12751 - 12775 of 24441

ID Name Category Price Stock Rating Reviews SKU
13310 Bulk Product 590633ef Sports & Outdoors $382.84 340 3.0 0 BULK-be986ce4
13311 Bulk Product 5977640d Sports & Outdoors $158.52 485 0.6 41 BULK-41f027b2
13312 Bulk Product 70644785 Clothing $661.19 353 1.3 76 BULK-ed72ba41
13313 Bulk Product 2507bad8 Electronics $711.35 485 4.8 86 BULK-ed190de3
13314 Bulk Product e35bd207 Clothing $20.97 378 4.4 44 BULK-99d80496
13315 Bulk Product 9a54f664 Clothing $790.30 218 4.3 94 BULK-926be75a
13316 Bulk Product 7c17fcd4 Toys & Games $880.02 341 2.2 5 BULK-b9866393
13317 Bulk Product 7542b5b0 Sports & Outdoors $742.35 98 3.0 67 BULK-fd1fd410
13318 Bulk Product aab72792 Home & Garden $393.35 405 1.8 39 BULK-cc8db0a7
13319 Bulk Product 1c3ac18e Toys & Games $805.98 131 3.7 24 BULK-f9aeaa9f
13320 Bulk Product f8a883e6 Electronics $631.23 60 1.9 59 BULK-557057a5
13321 Bulk Product e65f8e5d Clothing $604.30 5 1.2 37 BULK-5d3ca345
13322 Bulk Product c686077f Clothing $266.70 327 4.7 57 BULK-dc56aad2
13323 Bulk Product e87dc5bd Books $342.20 384 0.0 75 BULK-627f2080
13324 Bulk Product 5e257fad Toys & Games $80.96 273 1.9 60 BULK-cbe2c48d
13325 Bulk Product fe234b3b Home & Garden $403.02 451 3.3 76 BULK-bedeed4e
13326 Bulk Product 25766992 Books $133.97 193 3.0 99 BULK-0aec624e
13327 Bulk Product cf814636 Books $499.74 100 3.3 14 BULK-dd129059
13328 Bulk Product 7cbd3f45 Home & Garden $931.63 179 4.2 1 BULK-49cd3de3
13329 Bulk Product a14dedf9 Home & Garden $443.62 102 0.7 85 BULK-d88b91be
13330 Bulk Product 1d514545 Clothing $235.88 166 4.4 16 BULK-7c35b3a6
13331 Bulk Product 585e6417 Clothing $712.16 280 3.4 77 BULK-80027ba3
13332 Bulk Product 5fb002fb Toys & Games $670.35 322 3.7 6 BULK-d9ac92cc
13333 Bulk Product 4ce251eb Books $721.41 60 0.5 89 BULK-c7bee9a1
13334 Bulk Product f256d4b3 Books $374.72 351 1.6 83 BULK-101294de
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