

These parameters are used in “EmployeeData.cshtml” to define the routes for our page. After this, we have defined our parameter attributes - paramEmpID and action. We are injecting the HttpClient service to enable web API call and the IUriHelper service to enable URL redirection. We have defined a class EmployeeDataModel that will hold all our methods that we will use in the “EmployeeData.cshtml” page.
RAZOR CREATE TABLE TOOL CODE
Open “EmployeeDataAccessLayer.cs” and put the following code into it: using using Microsoft.EntityFrameworkCore using System using using System.Linq using namespace

Name your class “EmployeeDataAccessLayer.cs”. Right click on the “DataAccess” folder and select “Add” > “Class”. We will be adding our class to handle database-related operations inside this folder only. Right-click on the “BlazorSPA.Server” project and then select “Add” > “New Folder” and name the folder as “DataAccess”. Hence, we have successfully scaffolded our models using the Entity Framework core database first approach.Īt this point in time, the Models folder will have the following structure:Ĭreating the data access layer for the application It contains two class files, “myTestDBContext.cs” and “Employee.cs”. After this command is executed successfully, you can observe a “Models” folder has been created. Run the following command: Install-Package Īfter you have installed both the packages, we will scaffold our model from the database tables using the following command: Scaffold-DbContext "Your connection string here" -OutputDir Models -Tables Employeeĭo not forget to put your own connection string (inside “”).
RAZOR CREATE TABLE TOOL INSTALL
Since we are using Entity Framework Tools to create a model from the existing database, we will install the tools package as well. Run the following command: Install-Package Put the name of the project as “BlazorSPA” and press “OK”.įirst, we will install the package for the database provider that we are targeting, which is SQL Server in this case. Then, select “ASP.NET Core Web Application” from available project types. In the left panel, select “.NET Core” inside the Visual C# menu. Open Visual Studio and select “File” > “New” > “Project”.Īfter selecting the project, a “New Project” dialog will open. CREATE TABLE Employee ( EmployeeID int IDENTITY(1,1) PRIMARY KEY, Name varchar(20) NOT NULL, City varchar(20) NOT NULL, Department varchar(20) NOT NULL, Gender varchar(6) NOT NULL ) Create the Blazor web application Open SQL Server and use the following script to create the Employee table. We will be using a DB table to store all the records of employees. The Blazor framework is not supported by versions below Visual Studio 2017 v15.7.

install ASP.NET Core Blazor Language Services extension from here.install Visual Studio 2017 v15.7 or above from here.
