Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

55 ms

Page Size

25

Current Page

456 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 456 Results Showing 11376 - 11400 of 24441

ID Name Category Price Stock Rating Reviews SKU
11935 Bulk Product d369a692 Clothing $197.24 394 0.9 8 BULK-ecdf1e51
11936 Bulk Product 743fadc3 Books $635.44 454 4.4 56 BULK-659327c4
11937 Bulk Product 80c3da14 Electronics $710.81 284 4.2 77 BULK-fbd2525a
11938 Bulk Product d1a26551 Electronics $568.98 377 1.8 94 BULK-12476b0d
11939 Bulk Product c41ff9f7 Clothing $198.70 74 4.8 20 BULK-d82b3a8f
11940 Bulk Product b7961f33 Toys & Games $278.22 268 0.6 15 BULK-f743fd80
11941 Bulk Product f34c753f Clothing $391.41 133 2.3 38 BULK-bd3f803c
11942 Bulk Product 2cfe0b61 Home & Garden $430.23 233 4.3 38 BULK-f81d532e
11943 Bulk Product 93f7c466 Toys & Games $578.61 430 3.2 95 BULK-43c8c2e1
11944 Bulk Product 0bb162ab Toys & Games $130.43 21 2.3 9 BULK-c957f113
11945 Bulk Product bce8ec25 Sports & Outdoors $72.65 382 4.3 8 BULK-d23ec2d3
11946 Bulk Product 3dfecbe9 Toys & Games $452.86 180 0.3 10 BULK-6dd0f940
11947 Bulk Product 31adf0f2 Electronics $666.60 146 2.7 58 BULK-89208ed5
11948 Bulk Product ae610a3b Clothing $1,000.06 149 3.8 9 BULK-16e3dee3
11949 Bulk Product abe5c2b2 Home & Garden $694.05 67 2.4 62 BULK-d5f7b0c4
11950 Bulk Product fa31beec Toys & Games $394.05 108 3.4 74 BULK-c0f68c3a
11951 Bulk Product fea13e66 Books $152.57 186 2.5 23 BULK-ff2e3a68
11952 Bulk Product aa5b7d74 Toys & Games $990.33 342 4.1 95 BULK-29a866fa
11953 Bulk Product 53fe9c94 Sports & Outdoors $361.56 476 1.3 74 BULK-76250b0e
11954 Bulk Product 977a5264 Home & Garden $458.81 176 2.3 93 BULK-0eff5a67
11955 Bulk Product e2e7ee19 Books $66.52 306 3.8 54 BULK-2b112178
11956 Bulk Product c45e6b37 Books $69.76 335 4.4 88 BULK-af0c05a5
11957 Bulk Product afc4ce2e Electronics $874.54 308 0.7 43 BULK-69c66f0f
11958 Bulk Product ed616ad0 Electronics $256.99 271 0.1 18 BULK-89a771f4
11959 Bulk Product 7a267c91 Toys & Games $516.12 355 1.2 27 BULK-997922fe
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