EF CodeFirst:DropCreateDatabaseIfModelChanges不起作用 [英] EF CodeFirst: DropCreateDatabaseIfModelChanges doesn't work

查看:656
本文介绍了EF CodeFirst:DropCreateDatabaseIfModelChanges不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Global.asax中使用以下代码:

I use the following code in my Global.asax:

DbDatabase.SetInitializer<MyDBContext>
   (new DropCreateDatabaseIfModelChanges<MyDBContext>());

但似乎不起作用。

虽然我的模型已经改变,我正在尝试使用新添加的表之一,但它只是表示无法找到该表。

Although my Model has changed and I'm trying to use one of the newly added table's it just says the table could not be found.

Invalid object name 'dbo.TableName'.

如果我运行,但似乎工作,表正在创建:

If I run this however, it seems to work, and the table is being created:

DbDatabase.SetInitializer<MyDBContext>(new DropCreateDatabaseAlways<MyDBContext>());

它更新了我的数据库。

我做错了什么?

推荐答案

原来是主数据库的用户权限。很奇怪,使用DropCreateDatabaseAlways是不需要权限的主数据库,其中IfModelChanges。

It turned out to be user permissions on the master database. Weird that using DropCreateDatabaseAlways is doesn't need permissions on the master database, where IfModelChanges does.

这篇关于EF CodeFirst:DropCreateDatabaseIfModelChanges不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆