300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > Asp.net WebForm使用codeFirst建立和修改数据库小结

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

时间:2021-02-13 09:22:07

相关推荐

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

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

建立:

1、建立模型类

2、InPackage Manager Console, run the command:

enable-migrations -ContextTypeName ContosoUniversityModelBinding.Models.SchoolContext

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

4、Run the commandupdate-database

5、The database file has been added

修改:

1、修改模型类的字段

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

3、Therefore, openConfiguration.csin the Migrations folder and remove or comment out the code in theSeedmethod. Save and close the file.

4、Now, run the commandupdate-database.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。