Part 4 using entity framework

Step1: Install entity framework using nuget package manager.

Step2: Add a class file to the Models folder.(class name must equal connection string name and inherit DBContext,DBContext is in the namespace of System.Data.Entity)

Step3: Add a connection string, to the web.config file, in the root directory.

Step4: Map model class to the database table using "Table" atttibute.

Step5: Make the required changes to action method in controller.

Step6: Paste the following code in Application_Start() function in Global.asax file. Existing databases do not need, database initializer so it can be turned off.

Database.SetInitializer<{class name}>(null);
原文地址:https://www.cnblogs.com/gester/p/4856214.html