Perform CRUD Operations of Employee Form in ASP.NET Core MVC

How to perform CRUD operations of Employee Form in ASP.NET Core MVC Visual Studio 2022 step by step using scaffolding


Please Subscribe Youtube| Like Facebook | Follow Twitter

Video Tutorial: https://youtu.be/zM4V0dGD0QI

Introduction

In this article we will perform database CRUD operations of Employee form using scaffolding in visual studio 2022 (.Net 6.0) step by step.

Mens Contrast Patchwork Flap Pocket Decoration Short Sleeve T-Shirts

Steps

1. Open SQL Server and create database named Organization and SQL table named Employee with following queries

CREATE DATABASE Organization;

	USE Organization;	

	CREATE TABLE Employee  (
    		EmployeeID int NOT NULL IDENTITY(1,1) ,
    		DateOfBirth date NOT NULL,
    		EmployeeName  varchar(100) not null,
		FatheName  varchar(100) not null,
    		PRIMARY KEY (EmployeeID)
    
	);

2. Open Visual studio 2022 and create ASP.NET Core MVC Project

3. Install Required Nuget Packages

        Install-Package Microsoft.EntityFrameworkCore.SqlServer
	Install-Package Microsoft.EntityFrameworkCore.Tools
	Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design

4. Create Model from Existing Database by using following command which contains your SQL server name and database name

Scaffold-DbContext "Server=DESKTOP-CTNFVJO\SQLEXPRESS;Database=Organization;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

5. Add Controller with views

6. Go to Program.cs and add following line

builder.Services.AddDbContext<OrganizationContext>(options => options.UseSqlServer(@"server=DESKTOP-CTNFVJO\SQLEXPRESS;Database=Organization;Trusted_Connection=True;"));

7. Run and test your application

Note:

Need Support?

Please Subscribe Youtube| Like Facebook | Follow Twitter


Leave a Reply

Your email address will not be published. Required fields are marked *