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);

 

posted @ 2015-10-05 20:19  Gester.Lin  阅读(325)  评论(0编辑  收藏  举报