MVC + efcore project practice – warehouse management system 2 – build basic framework configuration efcore


This course officially enters the development part.

First of all, we should build the project framework first, or keep consistent with the previous progressive style. In addition to the necessary components, we should try our best to use native functions to facilitate our understanding.


Development tools: vs 2019 or above

Database: SQL Server 2017 or above


We will mention other items in the process of the project.


1、 New MVC project

1. Open vs 2019, create a new project, and select ASP.NET Core Web Application

2. Fill in the project name related information dwms


3. Select the MVC template and click create to complete the new project.

The project name dwms stands for data warehouse management system, that is, data warehouse management system.


2、 New page administrator

1. Right click the views / shared folder and select Add / new item


2. Select razor layout and fill in the template page name_ LayoutAdmin

We slightly modify the generated file and add the entry of CSS and JS, as shown in the following figure:

3、 Configure efcore

1. Install and configure EF

Enter nuget package manager and install the following two packages:




2. Create a new model to test EF

Open the folder models and add the class sysuser

By default, the table name generated by EF will be complex. We specify a singular table name at the beginning of the class: [table (“sysuser”)]

3. New operation context class

Create a new folder data to place EF related classes.

Create a new defaultcontext in the folder and inherit from dbcontext to manage the relationship between entities and tables in the database.


4. Add context to di and generate database

ASP.NET The core implements Di by default. The service is registered at startup and obtained by constructor.

4.1 open Startup.cs , register context in the box below




4.2 add the supporting defaultconnection below.

open appsettings.json File, add configuration section:

4.3 add test data and generate database structure

Create a new static class dbinitializer in the data folder, and add a new method initialization to initialize data.

Modify the main method in the program class and call our new initialize method



When you run the website with Ctrl + F5, you can see the existing data in the database.





In this tutorial, we built the basic framework of dwms (data warehouse management system). It includes new project, new administrator template page and efcore configuration

The configuration style of efcore 3. X is slightly different from that of efcore 2. X. it is placed in the main function of program (the previous 2.0 is generally placed in the config method in startup), so the separation of responsibilities is more clear.


I wish you all progress in your study:)