├── .gitignore ├── PaginationDemo.sln ├── README.md └── src ├── PaginationDemo.API ├── Configurations │ ├── DatabaseConfig.cs │ ├── DependencyInjectionConfig.cs │ └── Mappers │ │ ├── OrderProfile.cs │ │ ├── PagedResponseKeysetProfile.cs │ │ ├── PagedResponseProfile.cs │ │ └── ProductProfile.cs ├── Controllers │ ├── OrdersController.cs │ └── ProductsController.cs ├── Dtos │ ├── OrderResultDto.cs │ ├── PagedResponseKeysetDto.cs │ ├── PagedResponseOffsetDto.cs │ └── ProductResultDto.cs ├── PaginationDemo.API.csproj ├── PaginationDemo.API.http ├── Program.cs ├── Properties │ └── launchSettings.json ├── appsettings.Development.json └── appsettings.json ├── PaginationDemo.Domain ├── Interfaces │ ├── IOrderRepository.cs │ ├── IOrderService.cs │ ├── IProductRepository.cs │ ├── IProductService.cs │ └── IRepository.cs ├── Models │ ├── Entity.cs │ ├── Order.cs │ ├── PagedResponseKeyset.cs │ ├── PagedResponseOffset.cs │ └── Product.cs ├── PaginationDemo.Domain.csproj └── Services │ ├── OrderService.cs │ └── ProductService.cs └── PaginationDemo.Infrastructure ├── Context └── PaginationDemoDbContext.cs ├── PaginationDemo.Infrastructure.csproj └── Repositories ├── OrderRepository.cs ├── ProductRepository.cs └── Repository.cs /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.toptal.com/developers/gitignore/api/visualstudio,dotnetcore,csharp 2 | # Edit at https://www.toptal.com/developers/gitignore?templates=visualstudio,dotnetcore,csharp 3 | 4 | ### Csharp ### 5 | ## Ignore Visual Studio temporary files, build results, and 6 | ## files generated by popular Visual Studio add-ons. 7 | ## 8 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 9 | 10 | # User-specific files 11 | *.rsuser 12 | *.suo 13 | *.user 14 | *.userosscache 15 | *.sln.docstates 16 | 17 | # User-specific files (MonoDevelop/Xamarin Studio) 18 | *.userprefs 19 | 20 | # Mono auto generated files 21 | mono_crash.* 22 | 23 | # Build results 24 | [Dd]ebug/ 25 | [Dd]ebugPublic/ 26 | [Rr]elease/ 27 | [Rr]eleases/ 28 | x64/ 29 | x86/ 30 | [Ww][Ii][Nn]32/ 31 | [Aa][Rr][Mm]/ 32 | [Aa][Rr][Mm]64/ 33 | bld/ 34 | [Bb]in/ 35 | [Oo]bj/ 36 | [Ll]og/ 37 | [Ll]ogs/ 38 | 39 | # Visual Studio 2015/2017 cache/options directory 40 | .vs/ 41 | # Uncomment if you have tasks that create the project's static files in wwwroot 42 | #wwwroot/ 43 | 44 | # Visual Studio 2017 auto generated files 45 | Generated\ Files/ 46 | 47 | # MSTest test Results 48 | [Tt]est[Rr]esult*/ 49 | [Bb]uild[Ll]og.* 50 | 51 | # NUnit 52 | *.VisualState.xml 53 | TestResult.xml 54 | nunit-*.xml 55 | 56 | # Build Results of an ATL Project 57 | [Dd]ebugPS/ 58 | [Rr]eleasePS/ 59 | dlldata.c 60 | 61 | # Benchmark Results 62 | BenchmarkDotNet.Artifacts/ 63 | 64 | # .NET Core 65 | project.lock.json 66 | project.fragment.lock.json 67 | artifacts/ 68 | 69 | # ASP.NET Scaffolding 70 | ScaffoldingReadMe.txt 71 | 72 | # StyleCop 73 | StyleCopReport.xml 74 | 75 | # Files built by Visual Studio 76 | *_i.c 77 | *_p.c 78 | *_h.h 79 | *.ilk 80 | *.meta 81 | *.obj 82 | *.iobj 83 | *.pch 84 | *.pdb 85 | *.ipdb 86 | *.pgc 87 | *.pgd 88 | *.rsp 89 | *.sbr 90 | *.tlb 91 | *.tli 92 | *.tlh 93 | *.tmp 94 | *.tmp_proj 95 | *_wpftmp.csproj 96 | *.log 97 | *.tlog 98 | *.vspscc 99 | *.vssscc 100 | .builds 101 | *.pidb 102 | *.svclog 103 | *.scc 104 | 105 | # Chutzpah Test files 106 | _Chutzpah* 107 | 108 | # Visual C++ cache files 109 | ipch/ 110 | *.aps 111 | *.ncb 112 | *.opendb 113 | *.opensdf 114 | *.sdf 115 | *.cachefile 116 | *.VC.db 117 | *.VC.VC.opendb 118 | 119 | # Visual Studio profiler 120 | *.psess 121 | *.vsp 122 | *.vspx 123 | *.sap 124 | 125 | # Visual Studio Trace Files 126 | *.e2e 127 | 128 | # TFS 2012 Local Workspace 129 | $tf/ 130 | 131 | # Guidance Automation Toolkit 132 | *.gpState 133 | 134 | # ReSharper is a .NET coding add-in 135 | _ReSharper*/ 136 | *.[Rr]e[Ss]harper 137 | *.DotSettings.user 138 | 139 | # TeamCity is a build add-in 140 | _TeamCity* 141 | 142 | # DotCover is a Code Coverage Tool 143 | *.dotCover 144 | 145 | # AxoCover is a Code Coverage Tool 146 | .axoCover/* 147 | !.axoCover/settings.json 148 | 149 | # Coverlet is a free, cross platform Code Coverage Tool 150 | coverage*.json 151 | coverage*.xml 152 | coverage*.info 153 | 154 | # Visual Studio code coverage results 155 | *.coverage 156 | *.coveragexml 157 | 158 | # NCrunch 159 | _NCrunch_* 160 | .*crunch*.local.xml 161 | nCrunchTemp_* 162 | 163 | # MightyMoose 164 | *.mm.* 165 | AutoTest.Net/ 166 | 167 | # Web workbench (sass) 168 | .sass-cache/ 169 | 170 | # Installshield output folder 171 | [Ee]xpress/ 172 | 173 | # DocProject is a documentation generator add-in 174 | DocProject/buildhelp/ 175 | DocProject/Help/*.HxT 176 | DocProject/Help/*.HxC 177 | DocProject/Help/*.hhc 178 | DocProject/Help/*.hhk 179 | DocProject/Help/*.hhp 180 | DocProject/Help/Html2 181 | DocProject/Help/html 182 | 183 | # Click-Once directory 184 | publish/ 185 | 186 | # Publish Web Output 187 | *.[Pp]ublish.xml 188 | *.azurePubxml 189 | # Note: Comment the next line if you want to checkin your web deploy settings, 190 | # but database connection strings (with potential passwords) will be unencrypted 191 | *.pubxml 192 | *.publishproj 193 | 194 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 195 | # checkin your Azure Web App publish settings, but sensitive information contained 196 | # in these scripts will be unencrypted 197 | PublishScripts/ 198 | 199 | # NuGet Packages 200 | *.nupkg 201 | # NuGet Symbol Packages 202 | *.snupkg 203 | # The packages folder can be ignored because of Package Restore 204 | **/[Pp]ackages/* 205 | # except build/, which is used as an MSBuild target. 206 | !**/[Pp]ackages/build/ 207 | # Uncomment if necessary however generally it will be regenerated when needed 208 | #!**/[Pp]ackages/repositories.config 209 | # NuGet v3's project.json files produces more ignorable files 210 | *.nuget.props 211 | *.nuget.targets 212 | 213 | # Microsoft Azure Build Output 214 | csx/ 215 | *.build.csdef 216 | 217 | # Microsoft Azure Emulator 218 | ecf/ 219 | rcf/ 220 | 221 | # Windows Store app package directories and files 222 | AppPackages/ 223 | BundleArtifacts/ 224 | Package.StoreAssociation.xml 225 | _pkginfo.txt 226 | *.appx 227 | *.appxbundle 228 | *.appxupload 229 | 230 | # Visual Studio cache files 231 | # files ending in .cache can be ignored 232 | *.[Cc]ache 233 | # but keep track of directories ending in .cache 234 | !?*.[Cc]ache/ 235 | 236 | # Others 237 | ClientBin/ 238 | ~$* 239 | *~ 240 | *.dbmdl 241 | *.dbproj.schemaview 242 | *.jfm 243 | *.pfx 244 | *.publishsettings 245 | orleans.codegen.cs 246 | 247 | # Including strong name files can present a security risk 248 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 249 | #*.snk 250 | 251 | # Since there are multiple workflows, uncomment next line to ignore bower_components 252 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 253 | #bower_components/ 254 | 255 | # RIA/Silverlight projects 256 | Generated_Code/ 257 | 258 | # Backup & report files from converting an old project file 259 | # to a newer Visual Studio version. Backup files are not needed, 260 | # because we have git ;-) 261 | _UpgradeReport_Files/ 262 | Backup*/ 263 | UpgradeLog*.XML 264 | UpgradeLog*.htm 265 | ServiceFabricBackup/ 266 | *.rptproj.bak 267 | 268 | # SQL Server files 269 | *.mdf 270 | *.ldf 271 | *.ndf 272 | 273 | # Business Intelligence projects 274 | *.rdl.data 275 | *.bim.layout 276 | *.bim_*.settings 277 | *.rptproj.rsuser 278 | *- [Bb]ackup.rdl 279 | *- [Bb]ackup ([0-9]).rdl 280 | *- [Bb]ackup ([0-9][0-9]).rdl 281 | 282 | # Microsoft Fakes 283 | FakesAssemblies/ 284 | 285 | # GhostDoc plugin setting file 286 | *.GhostDoc.xml 287 | 288 | # Node.js Tools for Visual Studio 289 | .ntvs_analysis.dat 290 | node_modules/ 291 | 292 | # Visual Studio 6 build log 293 | *.plg 294 | 295 | # Visual Studio 6 workspace options file 296 | *.opt 297 | 298 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 299 | *.vbw 300 | 301 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 302 | *.vbp 303 | 304 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 305 | *.dsw 306 | *.dsp 307 | 308 | # Visual Studio 6 technical files 309 | 310 | # Visual Studio LightSwitch build output 311 | **/*.HTMLClient/GeneratedArtifacts 312 | **/*.DesktopClient/GeneratedArtifacts 313 | **/*.DesktopClient/ModelManifest.xml 314 | **/*.Server/GeneratedArtifacts 315 | **/*.Server/ModelManifest.xml 316 | _Pvt_Extensions 317 | 318 | # Paket dependency manager 319 | .paket/paket.exe 320 | paket-files/ 321 | 322 | # FAKE - F# Make 323 | .fake/ 324 | 325 | # CodeRush personal settings 326 | .cr/personal 327 | 328 | # Python Tools for Visual Studio (PTVS) 329 | __pycache__/ 330 | *.pyc 331 | 332 | # Cake - Uncomment if you are using it 333 | # tools/** 334 | # !tools/packages.config 335 | 336 | # Tabs Studio 337 | *.tss 338 | 339 | # Telerik's JustMock configuration file 340 | *.jmconfig 341 | 342 | # BizTalk build output 343 | *.btp.cs 344 | *.btm.cs 345 | *.odx.cs 346 | *.xsd.cs 347 | 348 | # OpenCover UI analysis results 349 | OpenCover/ 350 | 351 | # Azure Stream Analytics local run output 352 | ASALocalRun/ 353 | 354 | # MSBuild Binary and Structured Log 355 | *.binlog 356 | 357 | # NVidia Nsight GPU debugger configuration file 358 | *.nvuser 359 | 360 | # MFractors (Xamarin productivity tool) working folder 361 | .mfractor/ 362 | 363 | # Local History for Visual Studio 364 | .localhistory/ 365 | 366 | # Visual Studio History (VSHistory) files 367 | .vshistory/ 368 | 369 | # BeatPulse healthcheck temp database 370 | healthchecksdb 371 | 372 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 373 | MigrationBackup/ 374 | 375 | # Ionide (cross platform F# VS Code tools) working folder 376 | .ionide/ 377 | 378 | # Fody - auto-generated XML schema 379 | FodyWeavers.xsd 380 | 381 | # VS Code files for those working on multiple tools 382 | .vscode/* 383 | !.vscode/settings.json 384 | !.vscode/tasks.json 385 | !.vscode/launch.json 386 | !.vscode/extensions.json 387 | *.code-workspace 388 | 389 | # Local History for Visual Studio Code 390 | .history/ 391 | 392 | # Windows Installer files from build outputs 393 | *.cab 394 | *.msi 395 | *.msix 396 | *.msm 397 | *.msp 398 | 399 | # JetBrains Rider 400 | *.sln.iml 401 | 402 | ### DotnetCore ### 403 | # .NET Core build folders 404 | bin/ 405 | obj/ 406 | 407 | # Common node modules locations 408 | /node_modules 409 | /wwwroot/node_modules 410 | 411 | ### VisualStudio ### 412 | 413 | # User-specific files 414 | 415 | # User-specific files (MonoDevelop/Xamarin Studio) 416 | 417 | # Mono auto generated files 418 | 419 | # Build results 420 | 421 | # Visual Studio 2015/2017 cache/options directory 422 | # Uncomment if you have tasks that create the project's static files in wwwroot 423 | 424 | # Visual Studio 2017 auto generated files 425 | 426 | # MSTest test Results 427 | 428 | # NUnit 429 | 430 | # Build Results of an ATL Project 431 | 432 | # Benchmark Results 433 | 434 | # .NET Core 435 | 436 | # ASP.NET Scaffolding 437 | 438 | # StyleCop 439 | 440 | # Files built by Visual Studio 441 | 442 | # Chutzpah Test files 443 | 444 | # Visual C++ cache files 445 | 446 | # Visual Studio profiler 447 | 448 | # Visual Studio Trace Files 449 | 450 | # TFS 2012 Local Workspace 451 | 452 | # Guidance Automation Toolkit 453 | 454 | # ReSharper is a .NET coding add-in 455 | 456 | # TeamCity is a build add-in 457 | 458 | # DotCover is a Code Coverage Tool 459 | 460 | # AxoCover is a Code Coverage Tool 461 | 462 | # Coverlet is a free, cross platform Code Coverage Tool 463 | 464 | # Visual Studio code coverage results 465 | 466 | # NCrunch 467 | 468 | # MightyMoose 469 | 470 | # Web workbench (sass) 471 | 472 | # Installshield output folder 473 | 474 | # DocProject is a documentation generator add-in 475 | 476 | # Click-Once directory 477 | 478 | # Publish Web Output 479 | # Note: Comment the next line if you want to checkin your web deploy settings, 480 | # but database connection strings (with potential passwords) will be unencrypted 481 | 482 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 483 | # checkin your Azure Web App publish settings, but sensitive information contained 484 | # in these scripts will be unencrypted 485 | 486 | # NuGet Packages 487 | # NuGet Symbol Packages 488 | # The packages folder can be ignored because of Package Restore 489 | # except build/, which is used as an MSBuild target. 490 | # Uncomment if necessary however generally it will be regenerated when needed 491 | # NuGet v3's project.json files produces more ignorable files 492 | 493 | # Microsoft Azure Build Output 494 | 495 | # Microsoft Azure Emulator 496 | 497 | # Windows Store app package directories and files 498 | 499 | # Visual Studio cache files 500 | # files ending in .cache can be ignored 501 | # but keep track of directories ending in .cache 502 | 503 | # Others 504 | 505 | # Including strong name files can present a security risk 506 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 507 | 508 | # Since there are multiple workflows, uncomment next line to ignore bower_components 509 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 510 | 511 | # RIA/Silverlight projects 512 | 513 | # Backup & report files from converting an old project file 514 | # to a newer Visual Studio version. Backup files are not needed, 515 | # because we have git ;-) 516 | 517 | # SQL Server files 518 | 519 | # Business Intelligence projects 520 | 521 | # Microsoft Fakes 522 | 523 | # GhostDoc plugin setting file 524 | 525 | # Node.js Tools for Visual Studio 526 | 527 | # Visual Studio 6 build log 528 | 529 | # Visual Studio 6 workspace options file 530 | 531 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 532 | 533 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 534 | 535 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 536 | 537 | # Visual Studio 6 technical files 538 | 539 | # Visual Studio LightSwitch build output 540 | 541 | # Paket dependency manager 542 | 543 | # FAKE - F# Make 544 | 545 | # CodeRush personal settings 546 | 547 | # Python Tools for Visual Studio (PTVS) 548 | 549 | # Cake - Uncomment if you are using it 550 | # tools/** 551 | # !tools/packages.config 552 | 553 | # Tabs Studio 554 | 555 | # Telerik's JustMock configuration file 556 | 557 | # BizTalk build output 558 | 559 | # OpenCover UI analysis results 560 | 561 | # Azure Stream Analytics local run output 562 | 563 | # MSBuild Binary and Structured Log 564 | 565 | # NVidia Nsight GPU debugger configuration file 566 | 567 | # MFractors (Xamarin productivity tool) working folder 568 | 569 | # Local History for Visual Studio 570 | 571 | # Visual Studio History (VSHistory) files 572 | 573 | # BeatPulse healthcheck temp database 574 | 575 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 576 | 577 | # Ionide (cross platform F# VS Code tools) working folder 578 | 579 | # Fody - auto-generated XML schema 580 | 581 | # VS Code files for those working on multiple tools 582 | 583 | # Local History for Visual Studio Code 584 | 585 | # Windows Installer files from build outputs 586 | 587 | # JetBrains Rider 588 | 589 | ### VisualStudio Patch ### 590 | # Additional files built by Visual Studio 591 | 592 | # End of https://www.toptal.com/developers/gitignore/api/visualstudio,dotnetcore,csharp -------------------------------------------------------------------------------- /PaginationDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.8.34511.84 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PaginationDemo.API", "src\PaginationDemo.API\PaginationDemo.API.csproj", "{E76C7974-E8CA-4C94-8E01-FF30FBFBEC2C}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PaginationDemo.Domain", "src\PaginationDemo.Domain\PaginationDemo.Domain.csproj", "{77647D74-AA97-4375-9F02-7F2091A5B144}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PaginationDemo.Infrastructure", "src\PaginationDemo.Infrastructure\PaginationDemo.Infrastructure.csproj", "{6FCADBF3-5A7B-498C-89CA-772A9926F5FE}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {E76C7974-E8CA-4C94-8E01-FF30FBFBEC2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {E76C7974-E8CA-4C94-8E01-FF30FBFBEC2C}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {E76C7974-E8CA-4C94-8E01-FF30FBFBEC2C}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {E76C7974-E8CA-4C94-8E01-FF30FBFBEC2C}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {77647D74-AA97-4375-9F02-7F2091A5B144}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {77647D74-AA97-4375-9F02-7F2091A5B144}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {77647D74-AA97-4375-9F02-7F2091A5B144}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {77647D74-AA97-4375-9F02-7F2091A5B144}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {6FCADBF3-5A7B-498C-89CA-772A9926F5FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {6FCADBF3-5A7B-498C-89CA-772A9926F5FE}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {6FCADBF3-5A7B-498C-89CA-772A9926F5FE}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {6FCADBF3-5A7B-498C-89CA-772A9926F5FE}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {C2121EBA-9DDA-4BCC-9127-68CBAE94176C} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PaginationDemo 2 | This is a .NET 8 Web API project with an example of Offset and Keyset Pagination with EF Core. 3 | 4 | ## Article: 5 | - [Pagination in a .NET Web API with EF Core](https://henriquesd.medium.com/pagination-in-a-net-web-api-with-ef-core-2e6cb032afb7) 6 | -------------------------------------------------------------------------------- /src/PaginationDemo.API/Configurations/DatabaseConfig.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using PaginationDemo.Domain.Models; 3 | using PaginationDemo.Infrastructure.Context; 4 | 5 | namespace PaginationDemo.API.Configurations 6 | { 7 | public static class DatabaseConfig 8 | { 9 | public static void ConfigureDatabase(this IServiceCollection services, IConfiguration configuration) 10 | { 11 | services.AddDbContext(options => 12 | { 13 | options.UseSqlServer(configuration.GetConnectionString("DefaultConnection")); 14 | }); 15 | } 16 | 17 | public static void CreateDatabase(this IApplicationBuilder app) 18 | { 19 | using (var scope = app.ApplicationServices.CreateScope()) 20 | { 21 | var dbContext = scope.ServiceProvider.GetRequiredService(); 22 | dbContext.Database.EnsureCreated(); 23 | } 24 | } 25 | 26 | public static void PopulateDatabase(this IApplicationBuilder app) 27 | { 28 | using (var scope = app.ApplicationServices.CreateScope()) 29 | { 30 | var dbContext = scope.ServiceProvider.GetRequiredService(); 31 | 32 | var numberOfProductsToSeed = 100_000; 33 | var numberOfOrdersToSeed = 1_000; 34 | 35 | if (!dbContext.Products.Any()) 36 | { 37 | var products = Enumerable.Range(1, numberOfProductsToSeed).Select(i => new Product { Name = $"Product {i}" }); 38 | dbContext.Products.AddRange(products); 39 | dbContext.SaveChanges(); 40 | } 41 | 42 | if (!dbContext.Orders.Any()) 43 | { 44 | var orders = Enumerable.Range(1, numberOfOrdersToSeed).Select(i => new Order { Code = $"ORDER-{i}" }); 45 | dbContext.Orders.AddRange(orders); 46 | dbContext.SaveChanges(); 47 | } 48 | } 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /src/PaginationDemo.API/Configurations/DependencyInjectionConfig.cs: -------------------------------------------------------------------------------- 1 | using PaginationDemo.Domain.Interfaces; 2 | using PaginationDemo.Domain.Services; 3 | using PaginationDemo.Infrastructure.Repositories; 4 | 5 | namespace PaginationDemo.API.Configurations 6 | { 7 | public static class DependencyInjectionConfig 8 | { 9 | public static IServiceCollection ResolveDependencies(this IServiceCollection services) 10 | { 11 | services.AddScoped(); 12 | services.AddScoped(); 13 | 14 | services.AddScoped(); 15 | services.AddScoped(); 16 | 17 | return services; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/PaginationDemo.API/Configurations/Mappers/OrderProfile.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using PaginationDemo.API.Dtos; 3 | using PaginationDemo.Domain.Models; 4 | 5 | namespace PaginationDemo.API.Configurations.Mappers 6 | { 7 | public class OrderProfile : Profile 8 | { 9 | public OrderProfile() 10 | { 11 | CreateMap(); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /src/PaginationDemo.API/Configurations/Mappers/PagedResponseKeysetProfile.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using PaginationDemo.API.Dtos; 3 | using PaginationDemo.Domain.Models; 4 | 5 | namespace PaginationDemo.API.Configurations.Mappers 6 | { 7 | public class PagedResponseKeysetProfile : Profile 8 | { 9 | public PagedResponseKeysetProfile() 10 | { 11 | CreateMap(typeof(PagedResponseKeyset<>), typeof(PagedResponseKeysetDto<>)); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /src/PaginationDemo.API/Configurations/Mappers/PagedResponseProfile.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using PaginationDemo.API.Dtos; 3 | using PaginationDemo.Domain.Models; 4 | 5 | namespace PaginationDemo.API.Configurations.Mappers 6 | { 7 | public class PagedResponseProfile : Profile 8 | { 9 | public PagedResponseProfile() 10 | { 11 | CreateMap(typeof(PagedResponseOffset<>), typeof(PagedResponseOffsetDto<>)); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /src/PaginationDemo.API/Configurations/Mappers/ProductProfile.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using PaginationDemo.API.Dtos; 3 | using PaginationDemo.Domain.Models; 4 | 5 | namespace PaginationDemo.API.Configurations.Mappers 6 | { 7 | public class ProductProfile : Profile 8 | { 9 | public ProductProfile() 10 | { 11 | CreateMap(); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /src/PaginationDemo.API/Controllers/OrdersController.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using Microsoft.AspNetCore.Mvc; 3 | using PaginationDemo.API.Dtos; 4 | using PaginationDemo.Domain.Interfaces; 5 | 6 | namespace PaginationDemo.API.Controllers 7 | { 8 | [ApiController] 9 | [Route("api/[controller]")] 10 | public class OrdersController : ControllerBase 11 | { 12 | private readonly IOrderService _orderService; 13 | private readonly IMapper _mapper; 14 | 15 | public OrdersController(IMapper mapper, 16 | IOrderService orderService) 17 | { 18 | _mapper = mapper; 19 | _orderService = orderService; 20 | } 21 | 22 | [HttpGet("GetWithGenericOffsetPagination")] 23 | [ProducesResponseType(StatusCodes.Status200OK)] 24 | [ProducesResponseType(StatusCodes.Status400BadRequest)] 25 | public async Task GetWithGenericOffsetPagination(int pageNumber = 1, int pageSize = 10) 26 | { 27 | if (pageNumber <= 0 || pageSize <= 0) 28 | return BadRequest($"{nameof(pageNumber)} and {nameof(pageSize)} size must be greater than 0."); 29 | 30 | var pagedOrders = await _orderService.GetWithOffsetPagination(pageNumber, pageSize); 31 | 32 | var pagedOrdersDto = _mapper.Map>(pagedOrders); 33 | 34 | return Ok(pagedOrdersDto); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/PaginationDemo.API/Controllers/ProductsController.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using Microsoft.AspNetCore.Mvc; 3 | using PaginationDemo.API.Dtos; 4 | using PaginationDemo.Domain.Interfaces; 5 | 6 | namespace PaginationDemo.API.Controllers 7 | { 8 | [ApiController] 9 | [Route("api/[controller]")] 10 | public class ProductsController : ControllerBase 11 | { 12 | private readonly IProductService _productService; 13 | private readonly IMapper _mapper; 14 | 15 | public ProductsController(IMapper mapper, 16 | IProductService productService) 17 | { 18 | _mapper = mapper; 19 | _productService = productService; 20 | } 21 | 22 | [HttpGet("GetWithOffsetPagination")] 23 | [ProducesResponseType(StatusCodes.Status200OK)] 24 | [ProducesResponseType(StatusCodes.Status400BadRequest)] 25 | public async Task GetWithOffsetPagination(int pageNumber = 1, int pageSize = 10) 26 | { 27 | if (pageNumber <= 0 || pageSize <= 0) 28 | return BadRequest($"{nameof(pageNumber)} and {nameof(pageSize)} size must be greater than 0."); 29 | 30 | var pagedProducts = await _productService.GetWithOffsetPagination(pageNumber, pageSize); 31 | 32 | var pagedProductsDto = _mapper.Map>(pagedProducts); 33 | 34 | return Ok(pagedProductsDto); 35 | } 36 | 37 | [HttpGet("GetWithKeysetPagination")] 38 | [ProducesResponseType(StatusCodes.Status200OK)] 39 | [ProducesResponseType(StatusCodes.Status400BadRequest)] 40 | public async Task GetWithKeysetPagination(int reference = 0, int pageSize = 10) 41 | { 42 | if (pageSize <= 0) 43 | return BadRequest($"{nameof(pageSize)} size must be greater than 0."); 44 | 45 | var pagedProducts = await _productService.GetWithKeysetPagination(reference, pageSize); 46 | 47 | var pagedProductsDto = _mapper.Map>(pagedProducts); 48 | 49 | return Ok(pagedProductsDto); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /src/PaginationDemo.API/Dtos/OrderResultDto.cs: -------------------------------------------------------------------------------- 1 | namespace PaginationDemo.API.Dtos 2 | { 3 | public record OrderResultDto 4 | { 5 | public string Code { get; init; } 6 | } 7 | } -------------------------------------------------------------------------------- /src/PaginationDemo.API/Dtos/PagedResponseKeysetDto.cs: -------------------------------------------------------------------------------- 1 | namespace PaginationDemo.API.Dtos 2 | { 3 | public record PagedResponseKeysetDto 4 | { 5 | public int Reference { get; init; } 6 | public List Data { get; init; } 7 | } 8 | } -------------------------------------------------------------------------------- /src/PaginationDemo.API/Dtos/PagedResponseOffsetDto.cs: -------------------------------------------------------------------------------- 1 | namespace PaginationDemo.API.Dtos 2 | { 3 | public record PagedResponseOffsetDto 4 | { 5 | public int PageNumber { get; init; } 6 | public int PageSize { get; init; } 7 | public int TotalPages { get; init; } 8 | public int TotalRecords { get; init; } 9 | public List Data { get; init; } 10 | } 11 | } -------------------------------------------------------------------------------- /src/PaginationDemo.API/Dtos/ProductResultDto.cs: -------------------------------------------------------------------------------- 1 | namespace PaginationDemo.API.Dtos 2 | { 3 | public record ProductResultDto 4 | { 5 | public string Name { get; init; } 6 | } 7 | } -------------------------------------------------------------------------------- /src/PaginationDemo.API/PaginationDemo.API.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/PaginationDemo.API/PaginationDemo.API.http: -------------------------------------------------------------------------------- 1 | @PaginationDemo.API_HostAddress = https://localhost:7220 2 | 3 | # Products - Get with Offset Pagination; 4 | 5 | GET {{PaginationDemo.API_HostAddress}}/api/products/GetWithOffsetPagination?pageNumber=1&pageSize=5 6 | 7 | ### 8 | 9 | GET {{PaginationDemo.API_HostAddress}}/api/products/GetWithOffsetPagination/?pageNumber=20000&pageSize=5 10 | 11 | ### 12 | 13 | # Products - Get with Keyset Pagination; 14 | 15 | GET {{PaginationDemo.API_HostAddress}}/api/products/GetWithKeysetPagination?reference=0&pageSize=5 16 | 17 | ### 18 | 19 | GET {{PaginationDemo.API_HostAddress}}/api/products/GetWithKeysetPagination?reference=99995&pageSize=5 20 | 21 | ### 22 | 23 | # Orders - Get with Generic Pagination; 24 | 25 | GET {{PaginationDemo.API_HostAddress}}/api/orders/GetWithGenericOffsetPagination?pageNumber=1&pageSize=5 26 | 27 | ### 28 | 29 | GET {{PaginationDemo.API_HostAddress}}/api/orders/GetWithGenericOffsetPagination?pageNumber=2&pageSize=5 30 | -------------------------------------------------------------------------------- /src/PaginationDemo.API/Program.cs: -------------------------------------------------------------------------------- 1 | using PaginationDemo.API.Configurations; 2 | 3 | var builder = WebApplication.CreateBuilder(args); 4 | 5 | builder.Services.ConfigureDatabase(builder.Configuration); 6 | builder.Services.AddAutoMapper(typeof(Program)); 7 | builder.Services.ResolveDependencies(); 8 | 9 | builder.Services.AddControllers(); 10 | builder.Services.AddEndpointsApiExplorer(); 11 | builder.Services.AddSwaggerGen(); 12 | 13 | var app = builder.Build(); 14 | 15 | if (app.Environment.IsDevelopment()) 16 | { 17 | app.UseSwagger(); 18 | app.UseSwaggerUI(); 19 | } 20 | 21 | app.UseHttpsRedirection(); 22 | app.UseAuthorization(); 23 | app.MapControllers(); 24 | 25 | app.CreateDatabase(); 26 | app.PopulateDatabase(); 27 | 28 | app.Run(); -------------------------------------------------------------------------------- /src/PaginationDemo.API/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:51310", 8 | "sslPort": 44393 9 | } 10 | }, 11 | "profiles": { 12 | "http": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "http://localhost:5047", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "https": { 23 | "commandName": "Project", 24 | "dotnetRunMessages": true, 25 | "launchBrowser": true, 26 | "launchUrl": "swagger", 27 | "applicationUrl": "https://localhost:7220;http://localhost:5047", 28 | "environmentVariables": { 29 | "ASPNETCORE_ENVIRONMENT": "Development" 30 | } 31 | }, 32 | "IIS Express": { 33 | "commandName": "IISExpress", 34 | "launchBrowser": true, 35 | "launchUrl": "swagger", 36 | "environmentVariables": { 37 | "ASPNETCORE_ENVIRONMENT": "Development" 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/PaginationDemo.API/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/PaginationDemo.API/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "ConnectionStrings": { 10 | "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=PaginationDemo;Trusted_Connection=True;MultipleActiveResultSets=true" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/PaginationDemo.Domain/Interfaces/IOrderRepository.cs: -------------------------------------------------------------------------------- 1 | using PaginationDemo.Domain.Models; 2 | 3 | namespace PaginationDemo.Domain.Interfaces 4 | { 5 | public interface IOrderRepository : IRepository 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /src/PaginationDemo.Domain/Interfaces/IOrderService.cs: -------------------------------------------------------------------------------- 1 | using PaginationDemo.Domain.Models; 2 | 3 | namespace PaginationDemo.Domain.Interfaces 4 | { 5 | public interface IOrderService 6 | { 7 | Task> GetWithOffsetPagination(int pageNumber, int pageSize); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/PaginationDemo.Domain/Interfaces/IProductRepository.cs: -------------------------------------------------------------------------------- 1 | using PaginationDemo.Domain.Models; 2 | 3 | namespace PaginationDemo.Domain.Interfaces 4 | { 5 | public interface IProductRepository 6 | { 7 | Task> GetWithOffsetPagination(int pageNumber, int pageSize); 8 | Task> GetWithKeysetPagination(int reference, int pageSize); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/PaginationDemo.Domain/Interfaces/IProductService.cs: -------------------------------------------------------------------------------- 1 | using PaginationDemo.Domain.Models; 2 | 3 | namespace PaginationDemo.Domain.Interfaces 4 | { 5 | public interface IProductService 6 | { 7 | Task> GetWithOffsetPagination(int pageNumber, int pageSize); 8 | Task> GetWithKeysetPagination(int reference, int pageSize); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/PaginationDemo.Domain/Interfaces/IRepository.cs: -------------------------------------------------------------------------------- 1 | using PaginationDemo.Domain.Models; 2 | 3 | namespace PaginationDemo.Domain.Interfaces 4 | { 5 | public interface IRepository where TEntity : Entity 6 | { 7 | Task> GetWithOffsetPagination(int pageNumber, int pageSize); 8 | } 9 | } -------------------------------------------------------------------------------- /src/PaginationDemo.Domain/Models/Entity.cs: -------------------------------------------------------------------------------- 1 | namespace PaginationDemo.Domain.Models 2 | { 3 | public abstract class Entity 4 | { 5 | public int Id { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /src/PaginationDemo.Domain/Models/Order.cs: -------------------------------------------------------------------------------- 1 | namespace PaginationDemo.Domain.Models 2 | { 3 | public class Order : Entity 4 | { 5 | public string Code { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /src/PaginationDemo.Domain/Models/PagedResponseKeyset.cs: -------------------------------------------------------------------------------- 1 | namespace PaginationDemo.Domain.Models 2 | { 3 | public record PagedResponseKeyset 4 | { 5 | public int Reference { get; init; } 6 | public List Data { get; init; } 7 | 8 | // Other properties might be added; 9 | 10 | public PagedResponseKeyset(List data, int reference) 11 | { 12 | Data = data; 13 | Reference = reference; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /src/PaginationDemo.Domain/Models/PagedResponseOffset.cs: -------------------------------------------------------------------------------- 1 | namespace PaginationDemo.Domain.Models 2 | { 3 | public record PagedResponseOffset 4 | { 5 | public int PageNumber { get; init; } 6 | public int PageSize { get; init; } 7 | public int TotalRecords { get; init; } 8 | public int TotalPages { get; init; } 9 | public List Data { get; init; } 10 | 11 | // Other properties might be added; 12 | 13 | public PagedResponseOffset(List data, int pageNumber, int pageSize, int totalRecords) 14 | { 15 | Data = data; 16 | PageNumber = pageNumber; 17 | PageSize = pageSize; 18 | TotalRecords = totalRecords; 19 | TotalPages = (int)Math.Ceiling((decimal)totalRecords / (decimal)pageSize); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/PaginationDemo.Domain/Models/Product.cs: -------------------------------------------------------------------------------- 1 | namespace PaginationDemo.Domain.Models 2 | { 3 | public class Product : Entity 4 | { 5 | public string Name { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /src/PaginationDemo.Domain/PaginationDemo.Domain.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/PaginationDemo.Domain/Services/OrderService.cs: -------------------------------------------------------------------------------- 1 | using PaginationDemo.Domain.Interfaces; 2 | using PaginationDemo.Domain.Models; 3 | 4 | namespace PaginationDemo.Domain.Services 5 | { 6 | public class OrderService : IOrderService 7 | { 8 | private readonly IOrderRepository _orderRepository; 9 | 10 | public OrderService(IOrderRepository orderRepository) 11 | { 12 | _orderRepository = orderRepository; 13 | } 14 | 15 | public async Task> GetWithOffsetPagination(int pageNumber, int pageSize) 16 | { 17 | return await _orderRepository.GetWithOffsetPagination(pageNumber, pageSize); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/PaginationDemo.Domain/Services/ProductService.cs: -------------------------------------------------------------------------------- 1 | using PaginationDemo.Domain.Interfaces; 2 | using PaginationDemo.Domain.Models; 3 | 4 | namespace PaginationDemo.Domain.Services 5 | { 6 | public class ProductService : IProductService 7 | { 8 | private readonly IProductRepository _productRepository; 9 | 10 | public ProductService(IProductRepository productRepository) 11 | { 12 | _productRepository = productRepository; 13 | } 14 | 15 | public async Task> GetWithOffsetPagination(int pageNumber, int pageSize) 16 | { 17 | return await _productRepository.GetWithOffsetPagination(pageNumber, pageSize); 18 | } 19 | 20 | public async Task> GetWithKeysetPagination(int reference, int pageSize) 21 | { 22 | return await _productRepository.GetWithKeysetPagination(reference, pageSize); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/PaginationDemo.Infrastructure/Context/PaginationDemoDbContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using PaginationDemo.Domain.Models; 3 | 4 | namespace PaginationDemo.Infrastructure.Context 5 | { 6 | public class PaginationDemoDbContext : DbContext 7 | { 8 | public PaginationDemoDbContext(DbContextOptions options) : base(options) { } 9 | 10 | public DbSet Products { get; set; } 11 | public DbSet Orders { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /src/PaginationDemo.Infrastructure/PaginationDemo.Infrastructure.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | all 13 | runtime; build; native; contentfiles; analyzers; buildtransitive 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/PaginationDemo.Infrastructure/Repositories/OrderRepository.cs: -------------------------------------------------------------------------------- 1 | using PaginationDemo.Domain.Interfaces; 2 | using PaginationDemo.Domain.Models; 3 | using PaginationDemo.Infrastructure.Context; 4 | 5 | namespace PaginationDemo.Infrastructure.Repositories 6 | { 7 | // Example using a generic Offset Pagination from a generic Repository; 8 | public class OrderRepository : Repository, IOrderRepository 9 | { 10 | public OrderRepository(PaginationDemoDbContext context) : base(context) { } 11 | } 12 | } -------------------------------------------------------------------------------- /src/PaginationDemo.Infrastructure/Repositories/ProductRepository.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using PaginationDemo.Domain.Interfaces; 3 | using PaginationDemo.Domain.Models; 4 | using PaginationDemo.Infrastructure.Context; 5 | 6 | namespace PaginationDemo.Infrastructure.Repositories 7 | { 8 | public class ProductRepository : IProductRepository 9 | { 10 | private readonly PaginationDemoDbContext _dbContext; 11 | 12 | public ProductRepository(PaginationDemoDbContext dbContext) 13 | { 14 | _dbContext = dbContext; 15 | } 16 | 17 | public async Task> GetWithOffsetPagination(int pageNumber, int pageSize) 18 | { 19 | var totalRecords = await _dbContext.Products.AsNoTracking().CountAsync(); 20 | 21 | var products = await _dbContext.Products.AsNoTracking() 22 | .OrderBy(x => x.Id) 23 | .Skip((pageNumber - 1) * pageSize) 24 | .Take(pageSize) 25 | .ToListAsync(); 26 | 27 | var pagedResponse = new PagedResponseOffset(products, pageNumber, pageSize, totalRecords); 28 | 29 | return pagedResponse; 30 | } 31 | 32 | public async Task> GetWithKeysetPagination(int reference, int pageSize) 33 | { 34 | var products = await _dbContext.Products.AsNoTracking() 35 | .OrderBy(x => x.Id) 36 | .Where(p => p.Id > reference) 37 | .Take(pageSize) 38 | .ToListAsync(); 39 | 40 | var newReference = products.Count != 0 ? products.Last().Id : 0; 41 | 42 | var pagedResponse = new PagedResponseKeyset(products, newReference); 43 | 44 | return pagedResponse; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/PaginationDemo.Infrastructure/Repositories/Repository.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using PaginationDemo.Domain.Interfaces; 3 | using PaginationDemo.Domain.Models; 4 | using PaginationDemo.Infrastructure.Context; 5 | 6 | namespace PaginationDemo.Infrastructure.Repositories 7 | { 8 | // Example of a generic Offset Pagination in a generic Repository; 9 | public abstract class Repository : IRepository where TEntity : Entity 10 | { 11 | protected readonly PaginationDemoDbContext Db; 12 | 13 | protected Repository(PaginationDemoDbContext db) 14 | { 15 | Db = db; 16 | } 17 | 18 | public virtual async Task> GetWithOffsetPagination(int pageNumber, int pageSize) 19 | { 20 | var totalRecords = await Db.Set().AsNoTracking().CountAsync(); 21 | 22 | var entities = await Db.Set().AsNoTracking() 23 | .OrderBy(x => x.Id) 24 | .Skip((pageNumber - 1) * pageSize) 25 | .Take(pageSize) 26 | .ToListAsync(); 27 | 28 | var pagedResponse = new PagedResponseOffset(entities, pageNumber, pageSize, totalRecords); 29 | 30 | return pagedResponse; 31 | } 32 | } 33 | } 34 | --------------------------------------------------------------------------------