首页 > 数据库技术 > 详细

Asp.net WebForm使用codeFirst建立和修改数据库小结

时间:2016-12-04 16:27:41      阅读:199      评论:0      收藏:0      [点我收藏+]

在asp.net4.5框架下使用codeFirst添加和修改数据库文件小结。

建立:

1、建立模型类

2、In Package Manager Console, run the command:
enable-migrations -ContextTypeName ContosoUniversityModelBinding.Models.SchoolContext

3、系统自动产生configuration.cs文件,其中的seed方法用来初始化数据库

4、Run the command update-database

5、The database file has been added

修改:

1、修改模型类的字段

2、 In the Package Management window, add a migration by running the command add-migration AddEnrollmentDate. Notice that the migration code adds the new Datetime column to the Student table.

3、Therefore, open Configuration.cs in the Migrations folder and remove or comment out the code in the Seed method. Save and close the file.

4、Now, run the command update-database

 

Asp.net WebForm使用codeFirst建立和修改数据库小结

原文:http://www.cnblogs.com/xzitluyang/p/6130778.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!