Wednesday, July 29, 2020

ASP.NET Core – CRUD Using Angular And Entity Framework Core



Step - 1: Overview
In this article, I am going to create a web application using ASP.NET Core 3.1 and Angular 8.0 with the help of Entity Framework Core database first approach. I will be creating a sample Employee Record Management system. To read the inputs from the user, we are using Angular Forms with required field validations on the client-side. We are also going to bind a dropdown list in the Angular Form to a table in the database using EF Core. We will also learn how to deploy this application on IIS.

Step - 2 Required Tools
Install .NET Core 3.1 or above SDK from here.
Install the latest version of Visual Studio 2019 Community Edition from here.
Download and install the latest version of Node.js from here.
SQL Server 2008 or above.

We will be using Visual Studio 2017 and SQL Server 2012 or other like 2014, 2016, etc.

Step - 3 Database
We will be using two tables to store our data.

Employee: – Used to store the details of the employee. It contains fields such as EmployeeID, Name, City, Department, and Gender.
Cities: – This contains the list of cities and used to populate the City field of the Employee table. It contains two fields CityID and CityName.


CREATE TABLE Employee (
EmployeeID int IDENTITY(1,1) NOT NULL PRIMARY KEY,
Name varchar(20) NOT NULL ,
City varchar(20) NOT NULL ,
Department varchar(20) NOT NULL ,
Gender varchar(6) NOT NULL
)
GO
CREATE TABLE Cities (
CityID int IDENTITY(1,1) NOT NULL PRIMARY KEY,
CityName varchar(20) NOT NULL
)
GO
STEP - 4 Create MVC Web Application
Open Visual Studio and select File >> New >> Project.
After selecting the project, a “New Project” dialog will open. Select .NET Core inside the Visual C# menu
Then, select “ASP.NET Core 3.1 Web Application” from available project types. Put the name of the project as Proapp and press OK.e Model to the Application
We are using Entity Framework core database first approach to create our models. Navigate to Tools >> NuGet Package Manager >> Package Manager Console.
We have to install the package for the database provider that we are targeting which is SQL Server in this case. Hence run the following command:

Install-Package Microsoft.EntityFrameworkCore.SqlServer
Install-Package Microsoft.EntityFrameworkCore.Tools
Scaffold-DbContext "Your connection string here" Microsoft.EntityFrameworkCore.SqlServer -
OutputDir Models -Tables tblEmployee, tblCities








No comments:

Post a Comment

Rewrite whole Web Site System and Sub System with data migration to new system.

Can you please share me your skype id or whats up number for better communications  my skype id is - jitendra.tech  whats up - +919617741414...