NetCore 5 Pagination 100,000+ Rows
Introduction
Have you ever come across a web application where it is slow to display a data table? The crawling performance is typical in any application that has a lot of data. The amount of data plays a big role in how fast a table will load. The root cause of a slow site is “over-fetching” data.
The cure for “over-fetching” is server-side pagination — a programming technique for which only a subset of data, such as 10 rows, will be provided by the backend for display in the frontend.
Pagination, also known as paging, is the process of dividing a document into discrete pages, either electronic pages or printed pages. — Wikipedia
I recently published Angular 11 Pagination of 100,000+ Rows here in medium.com in which I mentioned the Visual Studio Template for rapid prototype REST API at the end. In this story, I will go over the OnionAPI template to scaffold a NetCore 5 solution with advanced features such as crud, sort, filter, and page, and then add custom code to support the Angular Datatables frontend.
Tutorial Content
The tutorial has three parts:
Part 1: Scaffold a REST API project using Visual Studio Template OnionAPI. Create a Clean Architecture solution running on NetCore 5 and seed the database with 100,000 rows of mock data using Bogus library.
Part 2: Design the REST API interfaces to work with Angular-Datatables. Review the input/out parameters and design strong-type C# interfaces.
Part 3: Build a custom REST endpoint for use by Angular Datatables. Add/update controller, CQRS, etc.
At the end of the tutorial part, I include a complementary screencast so you can see how it was done on my desktop. Grab a drink and relax while watching the video!
Related Tutorials
The focus of this tutorial is on the REST API backend. For the companion Angular frontend featuring pagination and CRUD, check out my other tutorials
- Angular 11 Pagination 100,000+ Rows
- Angular 11 CRUD with .Net 5 REST API Tutorial
- Angular 11 Modal Form, Dialog, and Toaster with Bootstrap
Opensource Project Highlights
VSIXTemplateOnionAPI is a Visual Studio template for scaffolding a clean architecture ASP.NET REST API solution that consists of five projects.
- Domain — Entities and the common models
- Application — Interfaces, CQRS Features, Exceptions, Behaviors
- Infrastructure.Persistence —Application-specific database access
- Infrastructure.Shared — Common services such as Mail Service, Date Time Service, Mock, and so on
- WebApi — Controllers for REST API resources and endpoints
The underline tech stack provides loosely-coupled and inverted-dependency architecture with good design patterns and practices. At the time of this writing, the OnionAPI template is at version 1.3 and can generate the REST API projects running on NetCore 5.
I created the OnionAPI template to refrain myself from DRY (Don’t repeat yourself). When starting a new project, I used to clone a working ASP.NET WebAPI project and changed the namespace, connection string, startup and deleted unused files. With the OnionAPI template, I specify a project name and it creates a clean project ready for Sprint 1. — Fuji Nguyen, Creator of OnionAPI Template
Prerequisites
The following tools/skills are recommended.
- Visual Studio 2019 Community — free editor for ASP.NET Core WebAPI C#.
- Familiarity with C# model classes and CQRS pattern.
Let’s get started!
Part 1: Scaffold a REST API project using Visual Studio Template OnionAPI.
The objective of Part 1 is to create a Clean Architecture solution and then seed the database with 100,000 rows of mock data.
By default, the OnionAPI template creates two REST resources:
- Employees — This is a mock REST API resource where the data is dynamically generated by the Bogus library at run time. To learn more about Bogus, check the link in the References section later on.
- Positions — This REST API resource gets its data from the actual database table Positions. This table is automatically seeded with 1,000 rows of mock data when the project first runs.
Task 1.1: Download OnionAPI Template
You can download the OnionAPI template from the Visual Studio Marketplace. See Figure 1 for more information.

After download, click on the VSIXTemplateOnionAPI.vsix to install the extension. If you are new to Visual Studio Extension, visit Manage extensions for Visual Studio for installation instructions.
Task 1.2: Generate a New REST API Project and seed database with 100,000 rows of position
The easiest way to create a new project is to start from a project template for a particular type of application or website. A project template consists of a basic set of pre-generated code files, config files, assets, and settings.
When you first open Visual Studio, the start window appears, and from there, you can choose to create a new project. See Figure 2 for more information.
If the Visual Studio development environment is already open, you can create a new project by choosing File > New > Project on the menu bar or by clicking the New Project button on the toolbar. See Figure 3 for more information.
Step 1: Select a Template Type
On the Create a new project page, a list of your recently selected templates appears on the left. The templates are sorted by most recently used.
If you’re not selecting from the recently used templates, you can filter all available project templates by entering text into the search box to further filter the templates; for example, enter in “OnionAPI”. See Figure 4 for more information.

Step 2: Create a Solution
On the Create a new project screen, search for and select the OnionAPI template and click on the Next button.

Enter the project name as AngularNgxDataTableBackend and location C:\apps\devkit\ApiResources then click on the Create button. See Figure 6 for visual aids. For folder naming convention, I recommend following the CAT Pattern.

Step 3: Set position seed value 100,000
Open ApplicationDbContext.cs from Infrastructure.Persistence > Contexts folder and change the SeedPositions from 1,000 to 100,000. See Figure 7 for visual aids.

Step 4: Run project
Hit F5 to run. Depending on the speed of your computer, it may take a minute or two to seed 100,000 position records. Then the swagger will display in the browser as shown in Figure 8.

Open and run the Positions > Get endpoint without entering any parameter. You should see the record total of 100,000 as shown in Figure 9.

Screencast of Part 1
The complementary Youtube video is a record of the steps in this part of the tutorial. If you find the video helpful, please like and subscribe.