Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

269 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 269 Results Showing 6701 - 6725 of 24441

ID Name Category Price Stock Rating Reviews SKU
7260 Bulk Product 8885e7cf Home & Garden $241.17 444 1.7 53 BULK-227b21fd
7261 Bulk Product dfe5b5bd Home & Garden $604.43 95 4.6 18 BULK-fd815662
7262 Bulk Product d7338650 Sports & Outdoors $308.91 105 4.5 54 BULK-610b4aa2
7263 Bulk Product f2eeab26 Toys & Games $450.94 228 0.3 11 BULK-1ffa6bb3
7264 Bulk Product e81f4b62 Clothing $414.47 495 3.3 44 BULK-b25b0ea3
7265 Bulk Product c3c815dc Electronics $398.05 141 4.9 50 BULK-2e070b44
7266 Bulk Product 188eba67 Books $908.32 345 4.9 87 BULK-57db583d
7267 Bulk Product 2ab32cdd Electronics $182.45 196 2.7 98 BULK-2c4c9905
7268 Bulk Product 20c2fa4b Clothing $433.67 150 2.9 8 BULK-ade441eb
7269 Bulk Product 79e03f4c Sports & Outdoors $913.32 467 4.6 28 BULK-e7f41ee2
7270 Bulk Product 7d774b12 Books $251.75 155 3.0 66 BULK-02fd747c
7271 Bulk Product 0bd8062f Electronics $128.59 174 3.6 5 BULK-9c0ce913
7272 Bulk Product a7f6dabb Home & Garden $93.97 138 1.6 37 BULK-936bf951
7273 Bulk Product fb4309ce Electronics $468.09 366 4.4 6 BULK-ff7bc5e9
7274 Bulk Product 8a00af99 Books $710.55 190 1.0 17 BULK-21ae1d98
7275 Bulk Product e4d12d28 Books $115.12 401 3.1 98 BULK-c3c95e2c
7276 Bulk Product 8882ef7a Home & Garden $750.41 117 3.4 20 BULK-ddb2741d
7277 Bulk Product c377596f Sports & Outdoors $37.97 2 4.2 11 BULK-43cf1804
7278 Bulk Product 03adf9bc Clothing $739.43 200 4.1 29 BULK-f3005f4a
7279 Bulk Product 7e82a64e Electronics $699.65 74 4.2 56 BULK-c5642ae1
7280 Bulk Product e4b43ec2 Books $750.01 6 4.4 38 BULK-181edc3e
7281 Bulk Product 691e69b2 Sports & Outdoors $345.87 448 1.3 1 BULK-b587734c
7282 Bulk Product 743e7596 Toys & Games $541.72 78 4.9 73 BULK-2c07e386
7283 Bulk Product 43d109a6 Home & Garden $16.51 60 2.3 97 BULK-1164751c
7284 Bulk Product 0bdb9780 Electronics $147.17 32 3.0 30 BULK-d4058f38
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