Briefly
We create a database and then generate the data model, add the ADO Entity Data Model, there are two ways commonly used, one is Dbfirst, one is codefirst, for simplicity, we use Dbfirst. A basic friend can use Codefirst, which has no effect on the project.
Project preparation
The tools we use are: VS + SQL Server + IIS7.5
I hope that we have a preliminary understanding of ASP. NET MVC, the theoretical things we do not do too much explanation, some places do not understand also does not matter, will use on the line, with more, with a long time, natural understanding.
Project start
First, create a database wkmvc_db
Create Database ... We will not talk about, can T-SQL (easy to transplant), I will use the most basic to create it ~ ~
Second, we create a user table
We create a user table because this user table I intend to use for the backend user, that is, the Administrator table, so we are called Sys_user
We add some field properties to this table
Database name: wkmvc_db table name: Sys_user
Serial number |
Column Name |
Data type |
Length |
Decimal digits |
Identity |
Primary key |
FOREIGN key |
Allow empty |
Default value |
Description |
1 |
Id |
Int |
4 |
0 |
Is |
Is |
|
Whether |
|
Primary Key ID |
2 |
NAME |
nvarchar |
50 |
0 |
|
|
|
Is |
|
real name |
3 |
Account |
nvarchar |
20 |
0 |
|
|
|
Is |
|
User account |
4 |
PASSWORD |
nvarchar |
1000 |
0 |
|
|
|
Is |
|
User password |
5 |
Iscanlogin |
Int |
4 |
0 |
|
|
|
Is |
|
Whether to lock (0 No 1 Yes) |
6 |
SHOWORDER1 |
Int |
4 |
0 |
|
|
|
Is |
|
Sorting within the Department |
7 |
SHOWORDER2 |
Int |
4 |
0 |
|
|
|
Is |
|
Sorting within the company |
8 |
PINYIN1 |
nvarchar |
50 |
0 |
|
|
|
Is |
|
Full name spell |
9 |
PINYIN2 |
nvarchar |
50 |
0 |
|
|
|
Is |
|
First Name character |
10 |
Face_img |
nvarchar |
200 |
0 |
|
|
|
Is |
|
User picture |
11 |
Levels |
nvarchar |
36 |
0 |
|
|
|
Is |
|
Level (docking Sys_code) |
12 |
Dptid |
nvarchar |
36 |
0 |
|
|
|
Is |
|
Main Department ID, department where the user is located |
13 |
Createper |
nvarchar |
36 |
0 |
|
|
|
Is |
|
Created by |
14 |
CreateDate |
Datetime |
8 |
3 |
|
|
|
Is |
|
Creation time |
15 |
UPDATEUSER |
nvarchar |
36 |
0 |
|
|
|
Is |
|
Modified by |
16 |
Updatedate |
Datetime |
8 |
3 |
|
|
|
Is |
|
Modification time |
17 |
Lastloginip |
nvarchar |
50 |
0 |
|
|
|
Is |
|
Last Login IP |
|
T-sql:
View Code
Then, we create a new login user Sa_wkmvc password is 123456, and add user mapping
Security → login name → new login name
Second, add the ADO Entity Data Model SQL_WKDB
In our domain, we add an ADO Entity Data model called SQL_WKDB
Right-click domain→ to add →ado.net Entity Data Model SQL_WKDB
Select the EF designer from the database (Dbfirst)
Next, and then click New Connection, because I am the local database, so my server name I write a., select Use SQL Server Authentication, and select or enter the name of the database we want to connect to
Click OK, then we change the connection settings profile, we save as entities
Select version
Change the model namespace to domain
OK, the Entity Data Model was created successfully!
Let's create a new configuration class MyConfig.cs for database connection string extraction (when you go to school, the teacher generally defines the const string strConnectionString in the public operation class DBHelper. configurationmanager.connectionstrings["sqlConnectionString"]. ConnectionString)
View Code
Oralce, we don't need my comment for the moment.
Next, we will create a common operation interface and implementation class, as well as spring injection, there is not much understanding of the early preview ~ ~ Again thank you for your attention, this thing is not a very mature thing, so, if you put forward a better solution or other problems, I will promptly revise.
Starting from 0, building a framework, doing a project (2) creating databases and data models