Speed Up ASP.NET Core Web API Development with EF Core Sidekick

Emma Maria
5 min readJan 24, 2025

--

Developing an ASP.NET Core Web API often involves repetitive tasks such as database configuration, DTO generation, and API scaffolding. These steps are essential but can consume valuable time that could be better spent solving real-world challenges. Thankfully, tools like EF Core Sidekick can simplify this process.

In this post, we’ll walk through creating a complete ASP.NET Core Web API with EF Core Sidekick in just minutes and explore how it can enhance your C# development workflow.

…………………………………………………………………………………………………

Prerequisites

Before diving in, ensure you have the following:

  1. Visual Studio 2022 installed with these workloads:
  • ASP.NET and Web Development
  • Data Storage and Processing

2. A database ready for connection (e.g., SQL Server, PostgreSQL, SQLite, etc.)

Prerequisites: Install Visual Studio 2022 and with Workloads

…………………………………………………………………………………………………

Step 1: Create an ASP.NET Core Web API Project

  1. Launch Visual Studio and create a new project.
  2. Select ASP.NET Core Web API from the project templates.
  3. Name your project , choose a location, and click Next.
  4. For the framework, select .NET 9 (or newer if available).
  5. Choose your API style:
  • Check “Use controllers” for traditional controller-based APIs.
  • Uncheck it for minimal APIs.

6. Click Create to generate the project.

Pro Tip for C# Developers: Opt for “Use controllers” if you’re working with a large team or need fine-grained control over routing logic. Minimal APIs are great for small, lightweight services.

Step 1: Create an ASP.NET Core Web API Project

…………………………………………………………………………………………………

Step 2: Set Up Your Database

Prepare your database with the necessary tables and data. For this demo, a simple database with Customers and Orders tables suffices.

Step 2: Set Up Your Database

…………………………………………………………………………………………………

Step 3: Install EF Core Sidekick

  1. Visit the EF Core Sidekick page and download the extension for free.
  2. This will redirect you to the Visual Studio Marketplace. Install the plugin and restart Visual Studio.

Why EF Core Sidekick? It eliminates repetitive tasks like scaffolding and DTO generation, freeing up your time for more complex coding challenges.

Step 3: Install EF Core Sidekick

…………………………………………………………………………………………………

Step 4: Generate Entities from the Database

  1. Right-click on your project in Solution Explorer.
  2. Navigate to Entity Framework Core Sidekick > New Entities from DB.
  3. Connect to your database:
  • If no servers are listed, retrieve your server name from SQL Server Management Studio and paste it into the connection dialog.
  • Select your database and click OK.

4. Choose the tables to include (e.g., Customers and Orders) and click Next.

5. Confirm the configurations and click Finish.

EF Core Sidekick generates the following:

  • Entity Classes: These classes map your database tables to C# objects, often including additional domain-specific logic or navigation properties to represent relationships between tables.
  • DbContext: The core component for querying and saving data, it also handles tasks such as change tracking and connection management, ensuring efficient database interactions.
Step 4: Generate Entities from the Database

…………………………………………………………………………………………………

Step 5: Generate DTOs

  1. Right-click on an entity (e.g., Customer) and select Generate DTO.
  2. Choose the columns to include and customize as needed:
  • Add custom code snippets, using statements, or inheritance directly within the Sidekick dialog.
Add Custom Code

3. Click Finish to generate the DTO.

DTOs are essential for clean code, decoupling your API’s data contract from the database model. They also mitigate over-posting vulnerabilities and improve security by limiting the data exposed through your API to only what is necessary.

Real-World Application: Use DTOs to expose only necessary data in APIs, enhancing security and performance by excluding unnecessary fields.

Step 5: Generate DTOs

…………………………………………………………………………………………………

Step 6: Scaffold API and Services

  1. Right-click on an entity and select Generate Services and APIs.
  2. Choose your options:
  • Generate CRUD operations.
  • Include or exclude the API layer.

3. Click Next to preview the generated code.

4. Inject custom code into the generated API controllers and services if needed.

5. Click Finish.

This process creates a cleanly organized API layer with services following single-responsibility principles.

Manual Coding Comparison: Manually writing CRUD operations for multiple entities can take hours. EF Core Sidekick does it in seconds, ensuring consistency and clean architecture.

Step 6: Scaffold API and Services

…………………………………………………………………………………………………

Step 7: Final Configuration

  1. Add the generated connection string to the appsettings.json file.
  2. Register the services and database context in Program.cs as per the generated instructions.
  3. (Optional) Set up Swagger for API testing and documentation. [Not available for.NET 9]
Step 7: Final Configuration

…………………………………………………………………………………………………

Results

Within minutes, you now have:

  • An ASP.NET Core Web API project.
  • Database-connected entity classes and DbContext.
  • Cleanly structured DTOs and services.
  • Fully scaffolded API controllers.

All of this with minimal effort, thanks to EF Core Sidekick!

Advanced Tip: Integrate Swagger or Postman to test and document your API endpoints effectively.

…………………………………………………………………………………………………

Why EF Core Sidekick?

  • Time-Saving: Drastically reduces setup time for new projects by automating repetitive tasks like scaffolding and DTO generation.
  • Customization Options: EF Core Sidekick allows seamless injection of custom code — like using statements, inheritance, or class attributes — into generated code, retaining these changes during regeneration for maintainable, adaptable projects.
  • Adherence to Best Practices: Follows clean code principles, making the codebase more maintainable and scalable.

If you’re looking for ways to reduce boilerplate code and streamline your development process, EF Core Sidekick is worth exploring.

You can download it here and try it out to see how it transforms your workflow.

Simplifying your workflow is critical in modern development. By automating mundane setup tasks, tools like EF Core Sidekick allow developers to focus on writing efficient and meaningful code. Whether you’re building a small API or a complex web application, these techniques can save time and effort while maintaining clean architecture.

Share your thoughts and experiences in the comments below — let’s learn and grow together!

For more tips and tricks on ASP.NET Core Web API development, check out my other posts and follow me for more updates!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Emma Maria
Emma Maria

Written by Emma Maria

Freelance Technical Writer with a passion for .NET related technology.

No responses yet

Write a response