Featured Article

Complete Guide to ASP NET Core CRUD Operations Example with Entity Framework Database First

Kenneth Jul 13, 2026

Mastering CRUD (Create, Read, Update, Delete) operations is fundamental to any application developer's skill set, and ASP.NET Core, with its integration with Entity Framework, offers a robust and efficient way to perform these operations. In this comprehensive guide, we'll delve into an illustrative example of ASP.NET Core CRUD operations using Entity Framework with a database-first approach.

the asp net core info sheet shows what it is like to work on an application
the asp net core info sheet shows what it is like to work on an application

Before we begin, ensure you have the following prerequisites in place: Visual Studio (community edition or above), .NET Core SDK, and a basic understanding of C#, databases, and the MVC pattern.

CRUD Operations using ADO.Net Entity Framework in Asp.Net MVC Example - Tutlane
CRUD Operations using ADO.Net Entity Framework in Asp.Net MVC Example - Tutlane

Setting Up the Project and Database Connection

The first order of business is to set up an ASP.NET Core application and configure the connection to your database. For this example, we'll use SQL Server, but the process is similar for other supported databases.

Code First Approach in Entity Framework in Asp.net MVC with Example - Tutlane
Code First Approach in Entity Framework in Asp.net MVC with Example - Tutlane

In Visual Studio, create a new ASP.NET Core Web Application. Choose the 'Individual User Accounts' authentication and 'MVC' project template. Then, add a new Data connection to your SQL Server database. Navigate to 'Data' > 'Show all tools' > 'Connect to Database', and choose 'SQL Server'.

Creating the Model and Data Access Layer

Introduction to Entity Framework Core - The Engineering Projects
Introduction to Entity Framework Core - The Engineering Projects

The Model-View-Controller (MVC) pattern separates an application into three main components. Let's start by creating a model for our data. We'll assume we're working with a simple 'Student' table containing 'Id', 'Name', and 'Age' columns.

right-click on your project, add a new 'ADO.NET Entity Data Model'. Name it 'ApplicationDbContext' and choose the ' fulfill database first from your database'. Select the 'Student' table and click 'Finish'. Azure_entityframework may create a new unit of work dbcontext file. EF's ADO.NET Entity Data Model was designed to address the gaps in ADO.NET.

Implementing CRUD Operations

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

Now that we have our model and data access layer set up, let's implement our CRUD operations using ASP.NET Core Controllers.

Routing andViewing Data

The next step is to set up routing so that our CRUD operations map to specific URLs and then create views to display the data.

𝗔𝗿𝗲 𝘆𝗼𝘂 𝘀𝘁𝗿𝘂𝗴𝗴𝗹𝗶𝗻𝗴 𝘄𝗶𝘁𝗵 𝗔𝘂𝘁𝗵𝗲𝗻𝘁𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗮𝗻𝗱 𝗔𝘂𝘁𝗵𝗼𝗿𝗶𝘇𝗮𝘁𝗶𝗼𝗻 𝗶𝗻 𝗔𝗦𝗣 .𝗡𝗘𝗧 𝗖𝗼𝗿𝗲? This guide helped a lot of developers Securing your… | Anton Martyniuk | 41 comments
𝗔𝗿𝗲 𝘆𝗼𝘂 𝘀𝘁𝗿𝘂𝗴𝗴𝗹𝗶𝗻𝗴 𝘄𝗶𝘁𝗵 𝗔𝘂𝘁𝗵𝗲𝗻𝘁𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗮𝗻𝗱 𝗔𝘂𝘁𝗵𝗼𝗿𝗶𝘇𝗮𝘁𝗶𝗼𝗻 𝗶𝗻 𝗔𝗦𝗣 .𝗡𝗘𝗧 𝗖𝗼𝗿𝗲? This guide helped a lot of developers Securing your… | Anton Martyniuk | 41 comments

In the 'Startup.cs' file, configure routing to map '/students' to GET 'GetStudents()', '/students/create' to GET 'Create()', and so on. Also, set up default routing for Edit and Delete methods.

Creating and Updating Students

an image of a computer screen with text and numbers on it, including the same language as
an image of a computer screen with text and numbers on it, including the same language as
A Step by Step Guide for ASP.NET Core Configuration
A Step by Step Guide for ASP.NET Core Configuration
an uml class diagram with multiple classes
an uml class diagram with multiple classes
Create ASP.NET Core Identity SQL Database Asp Dot Net Core Web API - Asp .Net core Web API - Part 2
Create ASP.NET Core Identity SQL Database Asp Dot Net Core Web API - Asp .Net core Web API - Part 2
a diagram showing the different types of web services and what they are used to create them
a diagram showing the different types of web services and what they are used to create them
a business model for product sales
a business model for product sales
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 blue and white resume with circles on the front, in font that reads'sq
a blue and white resume with circles on the front, in font that reads'sq
Tutorial - Creating a Contact Management Database (CRM) using Microsoft Access
Tutorial - Creating a Contact Management Database (CRM) using Microsoft Access

Add a new view for creating new 'Student' records. In the form, use HTML helpers to generate input fields for 'Name' and 'Age'. On submission, the form data will be automatically mapped to the 'Student' model.

Similarly, create an Edit view to update existing 'Student' records. Use the same approach with HTML helpers to bind form data to the 'Student' model.

Deleting Students

For deleting 'Student' records, create a 'Delete' view. Display the 'Student' data in a form and include a confirmation 'DELETE' button. When the user confirms, the 'DeleteStudent(int id)' method will be called.

The 'GetStudents()' method will populate a list of 'Student' objects into the view, which can then be displayed in a table format using a 'foreach' loop and HTML 'tr' and 'td' tags.

In conclusion, with this comprehensive example, you should now have a solid understanding of how to perform CRUD operations using ASP.NET Core and Entity Framework with a database-first approach. This knowledge is a powerful tool in your developer toolbox, enabling you to create robust and efficient web applications. Happy coding!