In this article I am going to walk you through CRUD operation using .net core 3.1 and entity framework core and SQL Server to store data. Here I will explain step by step how to Create, Read, Update and Delete employees from sql table using Rest API, EntityFramework core and sql server.
Before starting this there are a few prerequisites as below,
- Visual Studio 2019
- SQL server 2017
- .Net core 3.1
- Entity Framework core
- PostMan to test rest api.
Let's start with Visual Studio to create Rest API endpoint for Create, Read, Update and Delete method using core api 3.1.
- Start Visual Studio 2019 and click create a new project from the below screen.

- Once you click on a new project you will get a new screen to select Asp .Net Core Web Application from the below screen and click on next button.
- After clicking on the next button give a project name and location for your project where you want to save your project.
- Now we have the option to select framework and framework version as in the below screen, I have selected core and version core 3.1.
- After selecting the above option click on create. You are done with you new project for Rest API Core 3.1.

- Once you are done with new core api project, you will get default controller with Weatherforcast as below.

- Once you build your application then you should get the below screen by default. If you are getting the below screen then your solution is up and running.

- Now let's start with SQL server script to create table in database.
- CREATE TABLE [dbo].[Employees](
- [Id] [int] IDENTITY(1,1) NOT NULL,
- [FirstName] [varchar](50) NOT NULL,
- [LastName] [varchar](50) NOT NULL,
- [Email] [varchar](50) NOT NULL,
- [City] [varchar](50) NOT NULL,
- [Salary] [int] NOT NULL,
- PRIMARY KEY CLUSTERED
- (
- [Id] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
- Now let's create new folder as Model and add new class with name Employee under Model folder,
- using System.ComponentModel.DataAnnotations;
- namespace RestAPICoreDemo.Model
- {
- public class Employee
- {
- [Key]
- public int Id { get; set; }
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public string Email { get; set; }
- public string City { get; set; }
- public int Salary { get; set; }
- }
- }
- Now add EntityFrameworkCore package from nuget package manger. Install packages for Entity framework core
- Microsoft.EntityFrameworkCore.SqlServer











Khaja MoizuddinPosted May 4, 2024, 4:30 AM
Good one Jignesh Kumar,
Jose Sebastian Chacon AscuePosted Nov 26, 2021, 5:57 PM
Can you share your project folder? I'm getting a connection string error.
Yemane GebreyohansPosted Jul 1, 2021, 12:43 PM
How do i fix the connection string?
Barry AudsleyPosted Jun 23, 2021, 10:01 PM
This is one of the best articles and exercise to work through to learn the concepts of CRUD operation with .NET Core 3.1 and EF that I've come across! I only ran into one issue (due to a Transient error), but I was able to resolve that by modifying the ConnectionStrings database configuration in appsettings.json to fix it. Thank you!
JosephsPosted May 21, 2021, 5:10 AM
It is navigate weathcontroller only
Mitesh PatelPosted May 5, 2021, 9:46 PM
How the IIS take profile in production? The profile name should be same as dll name or it can be different as well?
Nikunj SatasiyaPosted Mar 8, 2021, 4:37 AM
Nice article Jignesh, Thank you for sharing with us.
Jeffrey BieseckerPosted Mar 5, 2021, 5:29 PM
Is there changes that are needed to the controller missing or I am making a mistake? I think modifications are needed to hit IEmployeeService?
Chittaranjan SwainPosted Mar 2, 2021, 4:05 PM
Nice article....
Hamid KhanPosted Mar 2, 2021, 6:37 AM
Nice article..............