Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

718 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 718 Results Showing 17926 - 17950 of 24441

ID Name Category Price Stock Rating Reviews SKU
18485 Bulk Product c41330a6 Home & Garden $256.78 200 4.3 60 BULK-ac4a9c14
18486 Bulk Product 0b09ec3c Toys & Games $332.67 81 4.2 17 BULK-eeb03fec
18487 Bulk Product b2f821f2 Sports & Outdoors $206.60 209 0.2 42 BULK-ad34c9e6
18488 Bulk Product 0c01a416 Books $478.86 460 0.8 78 BULK-a3bc0ed4
18489 Bulk Product fb9a66fc Clothing $379.42 318 0.2 64 BULK-36d5998b
18490 Bulk Product 7ef3d11a Electronics $381.81 179 0.8 97 BULK-e697a409
18491 Bulk Product 3b4cd5c1 Home & Garden $271.81 123 1.7 28 BULK-79e46bd1
18492 Bulk Product a3bd1775 Clothing $455.48 145 3.1 61 BULK-532a3e54
18493 Bulk Product 55859e3b Home & Garden $945.58 362 4.0 59 BULK-da8e4768
18494 Bulk Product e5dcec14 Clothing $1,006.65 214 0.4 36 BULK-13a2794d
18495 Bulk Product 1dee7821 Toys & Games $408.65 333 2.6 76 BULK-e0641122
18496 Bulk Product 19ebdfab Sports & Outdoors $449.02 369 2.3 71 BULK-fa306d3c
18497 Bulk Product 1588908e Toys & Games $408.77 42 1.1 3 BULK-c8fbf2b4
18498 Bulk Product acb64a47 Books $688.10 221 3.8 86 BULK-35d09fc9
18499 Bulk Product 0fc1f1b4 Clothing $745.64 210 0.8 94 BULK-48838079
18500 Bulk Product 347710fe Home & Garden $905.68 397 2.4 66 BULK-f439cadd
18501 Bulk Product ca6e9e5a Sports & Outdoors $499.10 411 5.0 7 BULK-c95e75eb
18502 Bulk Product 0370cb90 Books $638.18 455 0.0 73 BULK-8fb9dee1
18503 Bulk Product 9850ac8a Electronics $262.79 31 2.6 60 BULK-13f82b21
18504 Bulk Product be4f3800 Electronics $249.01 272 0.9 61 BULK-4c73f277
18505 Bulk Product 397da753 Books $51.71 16 3.6 41 BULK-9bf9fb1d
18506 Bulk Product 2fce9dfe Sports & Outdoors $333.25 287 2.9 91 BULK-4300816d
18507 Bulk Product 0e3902a1 Clothing $781.74 263 3.7 6 BULK-42dca09b
18508 Bulk Product a94761c4 Books $238.28 326 4.4 53 BULK-a2ec4832
18509 Bulk Product 023bf290 Electronics $854.42 88 0.3 7 BULK-44894954
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