Featured Article

Build a Complete ASP NET Core Entity Framework CRUD Example with Step by Step Guide

Kenneth Jul 13, 2026

Embarking on the journey of building modern, efficient web applications with ASP.NET Core? You're probably eager to incorporate Entity Framework (EF), Microsoft's popular ORM, for streamlined database interaction. Today, we'll delve into a comprehensive CRUD (Create, Read, Update, Delete) example using ASP.NET Core and Entity Framework Core (EF Core) to illustrate how these powerful tools can synergyize for robust, maintainable applications.

An introduction to OpenID Connect in ASP.NET Core
An introduction to OpenID Connect in ASP.NET Core

ASP.NET Core, a cross-platform, high-performance, open-source Framework, and Entity Framework Core, its lightweight, extensible, and cross-platform version of Entity Framework, combine to offer a powerful ecosystem for building enterprise-level applications. Now, let's dive into creating a simple CRM system, complete with CRUD operations, using ASP.NET Core and EF Core.

Web Application, 10 Things
Web Application, 10 Things

Setting Up the ASP.NET Core & EF Core Project

First, we'll initialize a new ASP.NET Core MVC project with individual user accounts:

Saeed Esmaeelinejad on LinkedIn: #entityframeworkcore #ef #dotnet #csharp | 30 comments
Saeed Esmaeelinejad on LinkedIn: #entityframeworkcore #ef #dotnet #csharp | 30 comments

```bash dotnet new mvc -n CRMApp --auth Individual ```

Next, add the Entity Framework Core library:

Using Stored Procedure CRUD Operations with Entity Framework Core || ASP.NET Core
Using Stored Procedure CRUD Operations with Entity Framework Core || ASP.NET Core

```bash cd CRMApp dotnet add package Microsoft.EntityFrameworkCore.Design dotnet add package Microsoft.EntityFrameworkCore.SqlServer ```

Creating the Database & Models

Create a new class 'CRMContext' to represent the 'DbContext' of our application, specifying the database connection and models:

GraphQL Mutation Query || Basic CRUD Example || ASP.NET Core || 2021
GraphQL Mutation Query || Basic CRUD Example || ASP.NET Core || 2021

```csharp public class CRMContext : DbContext { public CRMContext(DbContextOptions options) : base(options) { } public DbSet Customers { get; set; } } ```

Define customers and other necessary models using Data Annotations for validation:

Applying Migrations & Creating the Database

Complete Beginner CSS Master Notes
Complete Beginner CSS Master Notes

Apply migrations to create a corresponding database schema:

```bash dotnet ef migrations add InitialCreate dotnet ef database update ```

a flow diagram with several different types of items in it, including the name and number of
a flow diagram with several different types of items in it, including the name and number of
a table that shows the different types of software and services available for each individual device
a table that shows the different types of software and services available for each individual device
Complete Beginner CSS Master Notes
Complete Beginner CSS Master Notes
Complete Beginner CSS Master Notes
Complete Beginner CSS Master Notes
Design
Design
Conceptual Framework Template
Conceptual Framework Template
a screenshot of a family tree on a tablet screen with the words and numbers below it
a screenshot of a family tree on a tablet screen with the words and numbers below it
Organize Larger Queries With Frame Drop
Organize Larger Queries With Frame Drop
the flow diagram shows how to use guardrails in agilent workflows
the flow diagram shows how to use guardrails in agilent workflows

A 'CRMAppContext' and a 'CRM' database are now ready for action, with a table for 'Customers'.

Implementing the Repositories

Let's encapsulate CRUD operations within repository classes for good separation of concerns, starting with 'ICustomerRepository':

```csharp public interface ICustomerRepository { Task> GetAllAsync(); Task GetByIdAsync(int id); Task AddAsync(Customer customer); Task UpdateAsync(Customer customer); Task DeleteAsync(int id); } ```

Concrete Repository

Now, create the 'CustomerRepository' class utilizing the 'CRMContext' for database operations:

```csharp public class CustomerRepository : ICustomerRepository { private readonly CRMContext _context; public CustomerRepository(CRMContext context) { _context = context; } public async Task> GetAllAsync() { return await _context.Customers.ToListAsync(); } // Implement other CRUD methods... } ```

Initializing Repositories in the Startup.cs

Register the 'CustomerRepository' during service configuration:

```csharp services.AddScoped(); ```

Creating the Controllers

Build the slim, agile 'CustomersController' corresponding to customer-related API endpoints:

```csharp [Route("api/[controller]")] [ApiController] public class CustomersController : ControllerBase { private readonly ICustomerRepository _repository; public CustomersController(ICustomerRepository repository) { _repository = repository; } // GET: api/Customers [HttpGet] public async Task>> GetCustomers() { return await _repository.GetAllAsync(); } // HTTP CRUD methods for POST, PUT, DELETE... } ```

Testing the API

Utilize Postman or Swagger to verify the CRUD operations via API endpoints.

ASP.NET Core and Entity Framework Core have delicately partnered to present a fluid, dynamic CRUD example. You've now seen the swirl of essential concepts, from project setup to repository encapsulation and API-driven controllers. As we conclude, here's a recap: asp.net core entity framework crud example reflects best practices of ORM-infused web applications. Go forth, enhance upon this foundation, and build astounding apps!