数据库初始化程序还删除了我的会员表
我使用 aspnet_regsql 创建了数据库中的所有成员资格表。但是,我的初始化程序似乎正在删除成员资格表,
它是否有可能仅删除属于模型的表?
我想是因为这一行:
public class HRContextInitializer : DropCreateDatabaseAlways<HRContext>
{
I created using aspnet_regsql all the membership tables in my database. however it looks like my initializar is removing the membership tables also
Is it possible that it removes only the tables that belong to the model??
I suppose its because of this line:
public class HRContextInitializer : DropCreateDatabaseAlways<HRContext>
{
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,没错。您选择“DropCreateDatabaseAlways”初始化策略。您可以更改为“DropCreateDatabaseIfModelChanges”。
如果您的模型发生更改,EntityFramework 会尝试删除并重建数据库。
请查看 EntityFrameork.Migrations 以迁移更改而无需重建整个数据库。
Scott Hanselman 在他的博客中演示了这个很酷的新功能。
http://www.hanselman.com/blog/EntityFrameworkCodeFirstMigrationsAlphaNuGetPackageOfTheWeek10.aspx
和 Scott Guthries 博客关于 EntityFramework CodeFirst 的帖子
http://weblogs .asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx
Yes thats right. You choose the "DropCreateDatabaseAlways" initialization strategy. You can change to "DropCreateDatabaseIfModelChanges".
If your model change, EntityFramework try to delete and rebuild the database.
Please have a look at EntityFrameork.Migrations to migrate changes without rebuilding the whole database.
Scott Hanselman demos this cool new feature at his blog.
http://www.hanselman.com/blog/EntityFrameworkCodeFirstMigrationsAlphaNuGetPackageOfTheWeek10.aspx
And Scott Guthries Blog Post about EntityFramework CodeFirst
http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx