EF4代码首先创建新表 [英] EF4 Code First create new table
本文介绍了EF4代码首先创建新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
可以添加
Database.SetInitializer(new DropCreateDatabaseIfModelChanges< YourDbContext> ());你的应用程序启动
如果您修改了配置,它将为您重新创建数据库。
如果您不想删除并创建数据库(对于增量开发),您可以使用 SqlMigrations
。
Is there a way when i add a new entity to my Code First configuration the table gets automatically added so i don't have to worry about updating my DB with new tables?
解决方案
you can add
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<YourDbContext>());
in you r application start . It will recreate database for you if you have modified your configuration.
And if you do not want to drop and create database (To incremental development) you can use SqlMigrations
. http://www.hanselman.com/blog/EntityFrameworkCodeFirstMigrationsAlphaNuGetPackageOfTheWeek10.aspx
这篇关于EF4代码首先创建新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文